http://www.perlmonks.org?node_id=549855


in reply to strange behaviour when forking lots of times

The behaviour is attributable to running out of resource (specifically C stack) when spawning the threads that underlie Win32's fork emulation. The 1s appear to be residual values from Perl's stack, possibly the return from print, that are being 'assigned' to $_?

With a standard build of Perl, the 1s creep into the output when the number of concurrent forks (threads) exceeds ~120. Using AS811, using a string length of 9 exceeds this limit and produces a few ones at the end of the run

perl -le"fork || print qq[$$:$_] for split'', 'abcdefghi';" abcdbcdefghidefg ... [snip] 11h11h1111h1hh1111h1h11h11h11111i11h111111111111111i

However, if you used a copy of perl that has had it's stack reservation reduced as I described in Use more threads., then you can run many more concurrent threads, and the "strange behaviour" goes away. The following version succeeds in starting well over 13,000 threads before consuming all my swap space and terminating for lack of memory.

## WARNING. SERIOUS FORK BOMB tperl -e"fork || print for split'', 'abcdefghijklmnop';"

Reduce the string to 'a' .. 'n' and it completes successfully with no sign of the mysterious 1s.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.