Moritz doesn't mean to use the 'wait' command right after you fork (which would block till your child was done). The typical usage for wait is to execute it in response to a SIGCHLD signal:
sub reaper {
my $deadChildPID = wait;
print "Reaped child $deadChildPID\n";
}
$SIG{'CHLD'} = \&reaper;
# ..... some time later .....
if( $pid = fork() ) {
# begin FORK section
}
In any event, your dead children are waiting around as zombies for you to acknowledge their death. The zombies are preventing you from forking off more children. If you don't care about acknowledging their death, you can use something like this:
$SIG{CHLD}='IGNORE';
before you fork off any processes. This should work in Windows (and UNIX) to automatically reap your children without making a handler function. |