I think I've figured out what's going on. Corrections welcome.

When the child process allocates a new array reference via the push, that reference is automatically tied which causes the creation of a new shared memory segment and a new shared semaphore. See the section on "REFERENCES" in IPC::Shareable. By default, the "destroy" flag for those is off, so when the child exits, those segments live on.

When the parent exits gracefully, since it's "destroy" flag was on, all the shared memory and semaphores created by the parent are deleted. But that does not extend to the segments created by the children.

Adding a call to IPC::Shareable->clean_up_all() at the end of the parent causes all of the segments and semaphores (of both the parent and children) to go away. You would have to add that to the signal handler too.

Adding references to the tied structure is apparently very expensive, in terms of shared resources consumed. It would probably be best to find another way to do it.


In reply to Re: Leaking Semaphores and Shared Memory by gmargo
in thread Leaking Semaphores and Shared Memory by jcpunk

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.