while (@dead_kids <10) { sleep(1); } print "all kids dead .. @dead_kids\n"; #### #!/usr/bin/perl -w use strict; use POSIX qw(:signal_h :errno_h :sys_wait_h); $SIG{CHLD} = \&REAPER; my (@all_kids, @dead_kids); my @array = qw(a b c d e f g h); for (1 .. 10) { die "Bad Fork! $!\n" if ( !defined(my $pid = fork()) ); if ($pid ==0) #I'm child { my $t=int(rand(5))+1; print "@array sleeping $t secs\n"; sleep ($t); exit (0); } push (@all_kids, $pid); #I'm parent print "Starting another child process - $pid.\n"; } print "All child processes have started...\n"; print "kids: @all_kids\n"; my $count=0; while ($count <20) { sleep(1); $count++; } print "dead kids: @dead_kids\n"; print "All child processes are finished???\n"; sub REAPER { my $pid; while ( ($pid = waitpid(-1, WNOHANG)) > 0) #missed paren before { print "Process $pid exited.\n"; push @dead_kids, $pid; } return; }