Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

In reply to Re: strange behaviour when forking lots of times by BrowserUk
in thread strange behaviour when forking lots of times by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-29 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found