We create a child with Mojo::IOLoop::Subprocess that blocks for some time and then we send the parent a TERM, INT or HUP signal. The parent exits but the child continues to run. When the parent is interrupted from the keyboard all its children exit cleanly, but not so when the signal is sent from somewhere else. This will happen if you run the parent under a supervisor such as daemontools or runit and expect the whole bunch to exit when the parent exits.
use feature 'say';
# Operation that would block the event loop for 5 seconds
my $subprocess = Mojo::IOLoop::Subprocess->new;
my $subprocess = shift;
return '♥', 'Mojolicious';
my ($subprocess, $err, @results) = @_;
$pid = $subprocess->pid;
say "Subprocess $pid error: $err" and return if $err;
say "I $results $results!";
# Start event loop if necessary
$subprocess->ioloop->start unless $subprocess->ioloop->is_running;
We run this code send the parent the TERM signal before the child gets a chance to finish:
$ ps -j
ggl 4794 773 4794 0 1 S+ s003 0:00.20 perl ./blah.pl
ggl 4809 4794 4794 0 1 S+ s003 0:00.00 perl ./blah.pl
$ kill -TERM 4794
$ ps -j
USER PID PPID PGID SESS JOBC STAT TT TIME COMMAND
ggl 4809 1 4794 0 0 S s003 0:00.00 perl ./blah.pl
The parent should pass the signal to all of its children.
When the parent is signalled it exits, but of its children are left behind running.
I'm afraid this is the intended behavior, and there is no easy fix, Mojo::IOLoop::Subprocess is not meant for managing processes that run forever.
I'll leave this open a little bit longer so others have some time to chime in.
Doesn't appear there is much interest in this i'm afraid.