http://qs321.pair.com?node_id=1196897


in reply to Multiple forks with Proc::Daemon

No need for PID files if you don't daemonize the main process - systemd works best if the process doesn't daemonize. Systemd should be able to manage all children just fine and all you should need is a simple fork:

my @children; foreach my $server (@servers) { my $child = fork; die "Fork error" unless defined($child); if ($child) { push @children, $child; } else { do_stuff($server); } } waitpid($_) for @children;

The waitpid line will cause the main process to wait for all children before exiting (this is what systemd will use to know if any tasks are still running). You should be able to kill all remaining (stuck) processes using systemctl stop my-service (or if you want just a periodic run, periodically call systemctl restart my-service).

Good Day,
    Dean