
Parallel::Prefork - A simple prefork server framework

use Parallel::Prefork;
my $pm = Parallel::Prefork->new({
max_workers => 10,
trap_signals => {
TERM => 'TERM',
HUP => 'TERM',
USR1 => undef,
}
});
while ($pm->signal_received ne 'TERM') {
load_config();
$pm->start and next;
... do some work within the child process ...
$pm->finish;
}
$pm->wait_all_children();

Parallel::Prefork is much like Parallel::ForkManager, but supports graceful shutdown and run-time reconfiguration.

Instantiation. Takes a hashref as an argument. Recognized attributes are as follows.
number of worker processes (default: 10)
interval until next child process is spawned after a worker exits abnormally (default: 1)
hashref of signals to be trapped. Manager process will trap the signals listed in the keys of the hash, and send the signal specified in the associated value (if any) to all worker processes.
Coderef that is called when a child is reaped. Receives the instance to the current Paralle::Prefork, the child's pid, and its exit status.
The main routine. Returns undef in child processes. Returns a true value within manager process upon receiving a signal specified in the trap_signals hashref.
Child processes should call this function for termination. Takes exit code as an optional argument. Only usable from child processes.
Sends signal to all worker processes. Only usable from manager process.
Blocks until all worker processes exit. Only usable from manager process.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.