Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Multiple forks with Proc::Daemon

by duelafn (Vicar)
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,
    Dean

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-03-04 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (107 votes). Check out past polls.

    Notices?