In perl, killing child and its children when child was created using open
问题 Here's my code, with error handling and other stuff removed for clarity: sub launch_and_monitor { my ($script, $timeout) = @_; sub REAPER { while ((my $child = waitpid(-1, &WNOHANG)) > 0) {} $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER; my $pid = fork; if (defined $pid) { if ($pid == 0) { # in child monitor($timeout); } else { launch($script); } } } The launch sub executes a shell script which in turn launches other processes, like so: sub launch($) { my ($script) = @_; my $pid = open(PIPE,