The reason for this is not in the way that Perl is forking, but the way unix itself handles forking. I strongly recommend you get a set of the "Unix Network Programming" books by W. Richard Stevens if you do not already have them and plan on doing a lot of work with forking programs.

The reason that this memory problem is happening is that every time you fork, the two new processes are sharing the same memory pages, but they are sharing them on a copy-on-write fashion. So, the moment one of the two processes tries to update any data stored within a memory page, both processes end up getting their own copy of the entire page. This is a very efficient way of doing things when your children live for a short while and don't do much writing. However, the longer your children live (or the more your children need to write to memory), the less efficient this becomes.

If you have children that need to live for a very long time, you should evaluate your situation and decide wether you are better off in a forking environment, or if you would be better off working with threads.


In reply to Re: Perl program process by ehdonhon
in thread Perl program process by venki

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.