Hi,

Brandon, thanks for the explanation.

If I understand correctly, then this means Ctrl-C sends a SIGINT to
both the main process I ran and the child process I created using
Proc::Async.  When I run kill -2 PID it only sends the SIGINT to the
process I mentioned with PID.
(Which in my case was the process I ran.)

Then here is the problem which is closer to our original problem. I
have another script that uses Proc::Async to launch the previous
process. So now I have a main process, that has a child process which
has a child process.

use v6;
my $proc = Proc::Async.new($*EXECUTABLE, "async.pl6");
$proc.stdout.tap: -> $s { print $s };
my $promise = $proc.start;
sleep 10;
$proc.kill;

The "kill" there kill the immediate child but leaves the grandchild running.

Is there a way to send a signal to all the processes created by that
Proc::Async.new and to their children as well?

What I came up now is that changed the previous script (called
async.pl6) and added a line:

signal(SIGINT).tap( { say "Thank you for your attention"; $proc.kill } );

as below:

use v6;
my $proc = Proc::Async.new($*EXECUTABLE, "-e", "sleep 20000; say 'done'");
$proc.stdout.tap: -> $s { print $s };
my $promise = $proc.start;
signal(SIGINT).tap( { say "Thank you for your attention"; $proc.kill } );
await $promise;

Gabor

Reply via email to