Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Perl Signals

by afoken (Parson)
on Nov 14, 2011 at 10:10 UTC ( #937912=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl Signals
in thread Perl Signals

there is no need for "$SIG{"INT"} = "interrupt";" within interrupt() subroutine.

Interesting, because perlipc documents it this way:

or better still:
use POSIX ":sys_wait_h"; sub REAPER { my $child; # If a second child dies while in the signal handler caused by the # first death, we won't get another signal. So must loop here else # we will leave the unreaped child as a zombie. And the next time # two children die we get another zombie. And so on. while (($child = waitpid(-1, WNOHANG)) > 0) { $Kid_Status{$child} = $?; } $SIG{CHLD} = \&REAPER; # still loathe SysV } $SIG{CHLD} = \&REAPER; # do something that forks...

So, has perl's behaviour changed (when?), is one of SIGINT, SIGCHLD special for perl, or is perlipc simply out-of-date?

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re^2: Perl Signals
Download Code
Re^3: Perl Signals
by ikegami (Pope) on Nov 14, 2011 at 19:30 UTC

    Nothing to do with Perl.

    Some system remove the handler once it has caught a signal. If you want your program to handle more than one instance of the signal on those platforms, you need to set the handler again in the handler.

    I don't know what those systems are. Not your everyday systems. I think it's "SysV" systems, whatever that means.

Re^3: Perl Signals
by Marshall (Prior) on Nov 14, 2011 at 22:23 UTC
    Starting with 4.3BSD and System V Release 3, signal handlers remain installed after a signal occurs. So, yes, the requirement to re-install a signal handler is some super ancient (many decades ago) stuff. No modern system and no POSIX compliant system will cause an installed signal handler to be affected. I would think that the Perl docs should be updated.

    Now, this while() loop in the reaper is definitely needed! Signals are not "queued" for delivery. When a signal occurs, always interpret that to mean "at least one and maybe more than one of this signal has occurred".

    Update: Wiki ATT releases SVR3, SVR4. SVR3 was GA'ed in 1986. I figure after 25 years, we don't have to worry much about R2 any more!

      [...] the requirement to re-install a signal handler is some super ancient (many decades ago) stuff. [...] I would think that the Perl docs should be updated.

      So do I.

      this while() loop in the reaper is definitely needed

      I have no problem with the while loop in the reaper, it is properly explained in perlipc.

      On the other hand, so is the problem with old SysV behaviour:

      But that will be problematic for the more complicated handlers that need to reinstall themselves. Because Perl's signal mechanism is currently based on the signal(3) function from the C library, you may sometimes be so unfortunate as to run on systems where that function is "broken"; that is, it behaves in the old unreliable SysV way rather than the newer, more reasonable BSD and POSIX fashion. So you'll see defensive people writing signal handlers like this:

      I think the paragraph cited above and the two examples following it should be moved into a new section "Signal Handlers on Ancient Systems" ("pre-POSIX systems"?), and be replaced with text and examples that concentrate on handling SIGCHLD / wait / waitpid instead of working around ancient API problems.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://937912]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-11-28 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (193 votes), past polls