$SIG{CHLD} = \&waitforchildren; # reaper: sub waitforchildren { my $cpid; while ( ($cpid = waitpid(-1, &WNOHANG)) > 0 ) { $TrappedPIDs{$cpid} = WEXITSTATUS($?) if WIFEXITED($?); } } # processing routine ... foreach $pid ( keys(%TrappedPIDs) ) { # check return code for pid and do something } #### sub waitforchildren { my $cpid; my $pidlist = " "; while ( ($cpid = waitpid(-1, &WNOHANG)) > 0 ) { $TrappedPIDs{$cpid} = WEXITSTATUS($?) if WIFEXITED($?); } foreach $cpid ( keys(%TrappedPIDs) ) { $pidlist .= " ".$cpid; } print " TRAPPED PIDS: $pidlist \n"; }