sub REAPER { # takes care of dead children $SIG{CHLD} = \&REAPER; my $pid = wait; if ($pid > -1) { $children --; print "child $pid died, only $children left\n"; delete $children{$pid}; } else { $children = 0; } } #### # And maintain the population. while (1) { sleep; # wait for a signal (i.e., child's death) print "got woken up by signal\n"; for ($i = $children; $i < $PREFORK; $i++) { make_new_child(); # top up the child pool } }