Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Multiple forks with Proc::Daemon

by duelafn (Parson)
on Aug 07, 2017 at 12:31 UTC ( [id://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,
    Dean

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-20 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found