Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: strange behaviour when forking lots of times

by BrowserUk (Pope)
on May 16, 2006 at 18:49 UTC ( #549855=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://549855]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2019-12-11 08:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found