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"; }