> PROCESS 番号が 0 あるいは負数の場合の kill の振る舞いは オペレーティング > システムに依存します。
use 5.016; use warnings;
sub report { say $_[0], ': process ', (kill(0 => $_[0]) ? 'live?' : 'dead'); }
my $pid = fork; defined $pid or die "cannot fork: $!"; if (not $pid){ say "$$: child process"; say "$$: exit"; exit; }
say "$$: parent process"; sleep 1;
print grep{ /$pid/ } `ps ax`; report($pid);
say "$$: child($pid) wait..."; waitpid($pid, 0); report($pid);
結果(例:Debian) 28823: parent process 28824: child process 28824: exit 28824 pts/3 Z+ 0:00 [perl] <defunct> 28824: process live? 28823: child(28824) wait... 28824: process dead