Update
Sorry to update after closing, but I would have missed it if I hadn’t noticed that Parallel :: ForkManager also supports the run_on_start . This can be used to set the "baby registration" function, which takes care of the PID time() print for you.
eg.
$pm->run_on_start(sub { my $pid = shift; $workers{$pid} = time(); });
The result is that in combination with run_on_wait , as described below, the main P :: FM loop should not do anything special. That is, it can remain simple $pm->start and next , and callbacks will take care of the rest.
Original answer
Parallel :: ForkManager run_on_wait handler and a little bookkeeping can force to suspend and restore ALRM files for children.
The callback registered by this function can be executed periodically, and $pm waits for the completion of the child process.
use strict; use warnings; use Parallel::ForkManager; use constant PATIENCE => 90;
(Others claim that it’s best for the children to adjust themselves through alarm() , but this seems irregular for you. You can also resort to wasteful, crude hacks, such as having each child fork() or exec('bash', '-c', 'sleep 90; kill -TERM $PPID') .)
pilcrow
source share