Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Multiple forks with Proc::Daemon

by duelafn (Parson)
on Aug 07, 2017 at 12:31 UTC ( #1196897=note: print w/replies, xml ) Need Help??

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,

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1196897]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-12-06 01:32 GMT
Find Nodes?
    Voting Booth?

    No recent polls found