Each fork() duplicates the code that is running. All the variables are duplicated and they are each in a separate process - and most importantly they don't communicate with each other (except for the wait() call). They don't update each other's variables. Each child is acting like like a parent when it starts the next iteration of the loop.

The program you started is managing it's kids properly (limiting kids to 5). However, each child is also acting as a parent and managing kids. Their kids too. And so on.

You start with one process, that makes two, then four, then eight, etc.

This probably isn't what you intended ... you may want to check out a package by the name of Parallel::ForkManager. Find some sample code using that and you might find the light bulb.


In reply to Re: Help with Fork bomb by cursion
in thread Help with Fork bomb by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.