3
votes

Is there an option one can give to IPC::Run which kills the process upon the parent dying? Or alternatively a simple way to kill child processes when the parent dies? I know I can do this by catching signals in the parent, but I'd rather not reinvent the wheel if a simple way to do this already exists. I understand that this may not catch SIGKILL, but that's okay, I plan to kill the parent in a more reasonable manner.

1
You can use kill('HUP', -$$); in END block. This will kill parent and it's childs. - user966588

1 Answers

4
votes

Use an END block to clean up.

my @ipc_run_harnesses;
END { $_->kill_kill for @ipc_run_harnesses }

...
for my $start ( 1..2 ) {
    push @ipc_run_harnesses, IPC::Run::start( "while true; do sleep 1; echo running $start; done" );
}
sleep 10;
exit;