Created
June 29, 2012 05:52
-
-
Save nihen/3016093 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use 5.12.0; | |
use warnings; | |
use utf8; | |
use POSIX ':sys_wait_h'; | |
my $pid = fork(); | |
if ( $pid ) { | |
# parent | |
say "parent-start child_pid: $pid"; | |
sleep 1; | |
kill 'TERM' => $pid; | |
my $kid; | |
do { | |
$kid = waitpid(-1, WNOHANG); | |
} while $kid == 0; | |
#} while defined($kid) && $kid > 0; | |
say "kid: $kid"; | |
say "parent-end"; | |
} | |
else { | |
$SIG{TERM} = sub { say "TERM received" }; | |
say "child-start"; | |
sleep 3; | |
sleep 3; | |
say "child-end"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment