# Fork a child sub SPAWN { if ( $cpid = fork ) { $tracker{$cpid} = 1; } elsif ( defined $cpid ) { # do interesting things } else { die "What a world, what a world!"; } } # Spawn all your children SPAWN() for ( @jobs ); # Wait for them to die do { select( undef, undef, undef, 0.5 ); # 1/2 second sleep $counter++; $dpid = waitpid(-1,1); # non-blocking waitpid if ( defined( $dpid ) && $dpid != 1 ) { if ( defined( $tracker{$dpid} ) ) { print "Child $dpid is dead\n"; delete $tracker{$dpid}; } else { print "I am now terribly confused.\n"; } } until ( $dpid == -1 || $counter > 2000 ); if ( @temp = keys %tracker ) { print "Timed out while waiting for these pids:@temp\n"; }