Created
May 18, 2012 11:47
-
-
Save worldmind/2724846 to your computer and use it in GitHub Desktop.
Perl $SIG{CHLD} handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see http://perldoc.perl.org/perlipc.html#Signals | |
# http://www.calpoly.edu/cgi-bin/man-cgi?wait+2 | |
# and Perl Cookbook, part 16.19. Avoiding Zombie Processes | |
sub REAPER { | |
local ($!, $?); | |
while ( (my $pid = waitpid(-1, WNOHANG)) > 0 ) { | |
say "Process $pid send CHLD with status $?"; | |
if ( WIFEXITED($?) or WIFSIGNALED($?) ) { | |
if ( $kids{$pid} ) { | |
process_event_from_child( $kids{$pid}, 'chld' ); | |
} | |
else { | |
say "ERROR: CHLD signal from unknown PID $pid"; | |
} | |
} | |
else { | |
say "False CHLD alarm $? on $pid"; | |
} | |
} | |
$SIG{CHLD} = \&REAPER; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment