Hi Monks!

I have a problem and no idea how to solve it. I already spent some time googling and searching the monastery, but perhaps anyone can point me to the right node or site.

We have a script that builds up a large data structure and afterwards forks (we're on linux). The children do only read on that structure, so there is no need to copy it (which is important, because the machines don't have enough memory to handle a copy of the structure for each fork).

If we terminate the children using exit(), the structure is being copied for each child. If they get terminated using POSIX::_exit that will not happen. I think that is not nice and really would appreciate any other way to do that. Because I want an END block be called for each child and I don't have a clue, how to get this working.

If you wonder about that copy behavior, I prepared a small script, which proves the point (although i guess, most of you know it already). I watched my memory usage while execution and see a pretty high peak after the sleep if I alter the POSIX::_exit to a normal exit. Perhaps you need to adjust the array size for your computer...

#!/usr/bin/perl use strict; use warnings; use POSIX; my @array; for my $i (1 .. 100_000) { push @array, '-' x 1000; } print "before forking\n"; sleep 1; for (1 .. 10) { POSIX::_exit(0) unless fork; }

In reply to Memory consumption of forks on exit by egga

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.