Sten has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm strugling with fork(). After forking 64 times, it isn't forking anymore.
I wrote the following to illustrate my problem:
-------------------------------
#!C:\perl\bin\perl.exe $|= 1; my $counter= 1; while ($counter) { print "\n\nStart: $counter"; if( fork() eq 0 ) { countup($counter); exit; } print "\nEnd: $counter"; $counter++; sleep 1; } exit; sub countup { my $counter= shift; print "\nInFork: $counter"; return; }
---------------------------------

When running the script, the output goes like this:

***
***
Start: 63
End: 63
InFork: 63

Start: 64
End: 64
InFork: 64

Start: 65
End: 65

Start: 66
End: 66

***
***

Notice that the "InFork" line (and probably fork) is missing, starting from fork number 65.

Anyone who can help me out of this problem?
Regards
Sten

Replies are listed 'Best First'.
Re: Fork() win32 perl 5.8.4 ActiveState
by Anonymous Monk on Jan 19, 2007 at 13:34 UTC
    ActiveState Perl emulates the fork() function using threads. Their implementation has a limit of 64 due to the use of the Windows API method WaitForMultipleObjects(). This discussion of ActiveState's Perl fork() emulation may provide some more information.