alarm only works once??? 
Author Message
 alarm only works once???

The program below is supposed to repeated try to get input but stop
waiting for input after a couple of seconds.  After the first coupel
of seconds it times out.  After that alarm seems to have no effect.
Can anyone please tell my why this will only time out once and then
behave as if there were no alarm in the loop?

#!/usr/bin/perl  
sub justDie { print "timed out\n"; die; }
$SIG{ALRM}='justDie';
sub readit { <>; print "read input\n"; }
for (;;) {
    alarm 3;
    eval('&readit');

Quote:
}

--
==============================
Mark Grand
Independant Consultant

510-680-1252


Fri, 17 May 1996 00:37:04 GMT  
 alarm only works once???
I have found that the following problem happens under linux but not
solaris.  The only difference I know about between the interfaces of
the two is that under linux, the effects of signal seem to be cleared
after a signal handler is called, and under solaris it is not.

The program below is supposed to repeated try to get input but stop
waiting for input after a couple of seconds.  After the first coupel
of seconds it times out.  After that alarm seems to have no effect.
Can anyone please tell my why this will only time out once and then
behave as if there were no alarm in the loop?

#!/usr/bin/perl  
sub justDie { print "timed out\n"; die; }
$SIG{ALRM}='justDie';
sub readit { <>; print "read input\n"; }
for (;;) {
    alarm 3;
    eval('&readit');

Quote:
}

--
==============================
Mark Grand
Independant Consultant

510-680-1252
--
==============================
Mark Grand
Independant Consultant

510-680-1252


Fri, 17 May 1996 06:43:37 GMT  
 alarm only works once???
: The program below is supposed to repeated try to get input but stop
: waiting for input after a couple of seconds.  After the first coupel
: of seconds it times out.  After that alarm seems to have no effect.
: Can anyone please tell my why this will only time out once and then
: behave as if there were no alarm in the loop?
:
: #!/usr/bin/perl  
: sub justDie { print "timed out\n"; die; }
: $SIG{ALRM}='justDie';
: sub readit { <>; print "read input\n"; }
: for (;;) {
:     alarm 3;
:     eval('&readit');
: }

Works fine for me in both Perl 4 and 5.  Must be architecture dependent.

Larry



Fri, 17 May 1996 14:24:18 GMT  
 alarm only works once???
|> I have found that the following problem happens under linux but not
|> solaris.  The only difference I know about between the interfaces of
|> the two is that under linux, the effects of signal seem to be cleared
|> after a signal handler is called, and under solaris it is not.
|>
|> The program below is supposed to repeated try to get input but stop
|> waiting for input after a couple of seconds.  After the first coupel
|> of seconds it times out.  After that alarm seems to have no effect.
|> Can anyone please tell my why this will only time out once and then
|> behave as if there were no alarm in the loop?
|>
|> #!/usr/bin/perl  
|> sub justDie { print "timed out\n"; die; }
|> $SIG{ALRM}='justDie';
|> sub readit { <>; print "read input\n"; }
|> for (;;) {
|>     alarm 3;
|>     eval('&readit');
|> }

This behavior is architecture dependent :-).
On system V Unixes signal callbacks of the first 15 signals are forgotten after the signal
occures. You have to set $SIG{ALRM} before each alarm call or you can set it in the
signal callback.

                                                        Joachim



Fri, 17 May 1996 17:29:53 GMT  
 alarm only works once???

Quote:

> : Can anyone please tell my why this will only time out once and then
> : behave as if there were no alarm in the loop?

> Works fine for me in both Perl 4 and 5.  Must be architecture dependent.

It is OS dependent.  This is probably one of the most common problems for
people porting BSD sources to Linux.

Under Linux, the default behaviour is for the signal handler to be reset
when it is called.  Under BSD derived OS's (and probably others) the signal
handler is left alone.

I came across this first with a Perl script.  I remember asking if Perl
should provide:
   (a) `sticky' signal handlers across all platforms (by either
       resetting the handler itself, or appropriate flags to sigaction),
or (b) just provide the default behaviour of the underlying OS.

The only reply I got suggested the latter behaviour.  I, however, think the
former should be done -- how many Perl scripts are maximally portable by
resetting the signal handler when it is called?

--

[aka `Alfie'] | // ^ \\ | ..!uunet!mcsun!uknet!warwick!alfie



Fri, 17 May 1996 20:26:29 GMT  
 alarm only works once???



:> : Can anyone please tell my why this will only time out once and then
:> : behave as if there were no alarm in the loop?
:>
:> Works fine for me in both Perl 4 and 5.  Must be architecture dependent.
:
:It is OS dependent.  This is probably one of the most common problems for
:people porting BSD sources to Linux.
:
:Under Linux, the default behaviour is for the signal handler to be reset
:when it is called.  Under BSD derived OS's (and probably others) the signal
:handler is left alone.
:
:I came across this first with a Perl script.  I remember asking if Perl
:should provide:
:   (a) `sticky' signal handlers across all platforms (by either
:       resetting the handler itself, or appropriate flags to sigaction),
:or (b) just provide the default behaviour of the underlying OS.
:
:The only reply I got suggested the latter behaviour.  I, however, think the
:former should be done -- how many Perl scripts are maximally portable by
:resetting the signal handler when it is called?

I know the BUGS section says:
     Perl is at the mercy of your machine's definitions of  various
     operations such as type casting, atof() and sprintf().

But I believe that I'm now in the (a) camp.  Perl provides for a way to do
things like rename() and truncate() and mkdir() irrespective of the
underlying operating system.  Perl emulates system() and popen().  It
would be much easier if it did sticky signals as well rather than just
punting and letting the operating system decide, because that makes it harder
to write portable programs.

The interrupted syscall behaviour is also a pain to code around.

--tom
--

      "Will Hack Perl for Fine Food and Fun"
        Boulder Colorado  303-444-3212



Fri, 17 May 1996 21:12:17 GMT  
 alarm only works once???



: :> : Can anyone please tell my why this will only time out once and then
: :> : behave as if there were no alarm in the loop?
: :>
: :> Works fine for me in both Perl 4 and 5.  Must be architecture dependent.
: :
: :It is OS dependent.  This is probably one of the most common problems for
: :people porting BSD sources to Linux.
: :
: :Under Linux, the default behaviour is for the signal handler to be reset
: :when it is called.  Under BSD derived OS's (and probably others) the signal
: :handler is left alone.
: :
: :I came across this first with a Perl script.  I remember asking if Perl
: :should provide:
: :   (a) `sticky' signal handlers across all platforms (by either
: :       resetting the handler itself, or appropriate flags to sigaction),
: :or (b) just provide the default behaviour of the underlying OS.
: :
: :The only reply I got suggested the latter behaviour.  I, however, think the
: :former should be done -- how many Perl scripts are maximally portable by
: :resetting the signal handler when it is called?

: I know the BUGS section says:
:      Perl is at the mercy of your machine's definitions of  various
:      operations such as type casting, atof() and sprintf().

: But I believe that I'm now in the (a) camp.  Perl provides for a way to do
: things like rename() and truncate() and mkdir() irrespective of the
: underlying operating system.  Perl emulates system() and popen().  It
: would be much easier if it did sticky signals as well rather than just
: punting and letting the operating system decide, because that makes it harder
: to write portable programs.

: The interrupted syscall behaviour is also a pain to code around.

If Perl used the POSIX signal handling routines by default (if they were available)
would that allow for a more consistent behavior across platforms? My recollection of
their functionality says that they would, but then again my recollection tends
to tell me just what I want to hear :-)

An added bonus is that the POSIX signal handler does have a richer functionality.
Integrating this functionality into the signal model Perl uses would require a
bit of thought.

As an experiment in using usubs, I did hack the Perl source a while back to add
some of the POSIX calls (sigprocmask, sigaction, sigpending...), but I didn't
get the time to make the %SIG array and all the other internals which
make use of signals changed over.

Should POSIX signals be considered for Perl 5?
Would this added functionality be of use to anyone?

Paul



Sat, 18 May 1996 19:10:32 GMT  
 alarm only works once???

:Should POSIX signals be considered for Perl 5?
:Would this added functionality be of use to anyone?

(Yes) x 2

Also, the tc[sg]etattr() and cf*() functions.

--tom

--

      "Will Hack Perl for Fine Food and Fun"
        Boulder Colorado  303-444-3212



Sat, 18 May 1996 20:21:24 GMT  
 alarm only works once???

: :Should POSIX signals be considered for Perl 5?
: :Would this added functionality be of use to anyone?

: (Yes) x 2

: Also, the tc[sg]etattr() and cf*() functions.

So what are the chances of us actually getting any/all of
these in Perl 5?

Paul



Sat, 18 May 1996 21:19:40 GMT  
 alarm only works once???

:: Also, the tc[sg]etattr() and cf*() functions.
:
:So what are the chances of us actually getting any/all of
:these in Perl 5?

Depends on which patchlevel and by when. :-)

--tom
--

      "Will Hack Perl for Fine Food and Fun"
        Boulder Colorado  303-444-3212



Sun, 19 May 1996 03:02:09 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. alarm/$SIG{'ALRM'} works once only in wwwhttp.pl under Linux

2. Using alarm in Perl CGI script not working

3. Alarm not working with network calls, LWP

4. HELP! alarm doesn't work during gethostbyaddr()

5. alarm(n) works but not consistently .....

6. Alarm not working

7. How does ALARM signal handling work?

8. signal/eval/alarm problem Perl 5.002b2 Solaris 2.5 (works on SunOS and Linux)

9. Working with two streams at once: ack pth!

10. kill -HUP only works once

11. grep() only works once on an open file?

12. Help with alarm() on Solaris 9 (64-bit)

 

 
Powered by phpBB® Forum Software