while ((my $pid = waitpid(-1, &WNOHANG)) > 0) { $children--; # need this to tell when we're done $exits{$pid} = $?; # need this to see the problem }