Skip to content

Instantly share code, notes, and snippets.

@nihen
Created June 29, 2012 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nihen/3016093 to your computer and use it in GitHub Desktop.
Save nihen/3016093 to your computer and use it in GitHub Desktop.
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