ncw has asked for the wisdom of the Perl Monks concerning the following question:
use strict; $|=1; my $forked = 0; $SIG{CHLD} = \&REAPER; # set handler for fork for (1..10) { my $pid = fork(); die "Fork failed" unless defined $pid; if ($pid == 0) { print "Hello $$\n"; sleep 1; print "Bye $$\n"; exit; } else { $forked++; print "Started child $pid\n"; } } print "Waiting for children to finish.."; while ($forked > 0) { print "[$forked] "; sleep 1; } print "Done\n"; exit; sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; # reinstall for sysV (not needed) print "Finished child process $pid" . ($? ? " with exit $?" : "") +. "\n"; $forked--; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POSIX and sigaction
by chromatic (Archbishop) on Aug 24, 2000 at 19:57 UTC | |
|
Re: POSIX and sigaction
by merlyn (Sage) on Aug 24, 2000 at 18:40 UTC | |
|
RE: POSIX and sigaction
by mikfire (Deacon) on Aug 24, 2000 at 19:57 UTC |