http://www.perlmonks.org?node_id=891122


in reply to Check if forked process is dead

It works now. Thanks all.
$ perl -Mstrict -MPOSIX -wE 'my $pid = fork; if( $pid ){ kill TERM => +$pid; foreach( 1..5 ){ sleep 1; waitpid $pid => WNOHANG; my $rv = kil +l 0 => $pid; say $rv; exit unless $rv; } kill KILL => $pid; waitpid $ +pid => 0; } else { BEGIN{ $SIG{TERM}=sub{ say "TERM!"; }; } sleep 3; + exit; }' TERM! 1 1 0 $ perl -Mstrict -MPOSIX -wE 'my $pid = fork; if( $pid ){ kill TERM => +$pid; foreach( 1..3 ){ sleep 1; waitpid $pid => WNOHANG; my $rv = kil +l 0 => $pid; say $rv; exit unless $rv; } kill KILL => $pid; waitpid $ +pid => 0; } else { BEGIN{ $SIG{TERM}=sub{ say "TERM!"; }; } sleep 5; + exit; }' TERM! 1 1 1 $