"until %pids is empty." means either "sleep()" call or 100% cpu "while(1)" loop … But this would be just workaround over non-working wait() call.

Actually, sleep without an argument translates to "sleep forever" (until interrupted). So sleep while %pids; consumes almost no CPU1, as it will only check %pids when it's interrupted, likely by the very SIGCHLD you would like to trigger a check of %pids. You can't get much more optimal than that. I don't consider this common idiom a "workaround" at all, especially if you were just going to wait() in your main loop anyway (wait/waitpid get interrupted just like sleep, but Perl ensures they're transparently re-started after the signal handler returns). See Restartable System Calls (perlipc) for more information.

If you still have reservations, you can always exit from your signal handler (as I think you may already have been doing in one of your examples) once it removes the last key from %pids, but then that leaves the question of what you are planning to do in your main loop: if you're just going to sleep or block, you probably won't gain anything.

I hope this helps.

___________
1. Sure, pathological situations with a (very) large flood of incoming signals would tax the CPU, but in that case, checking the size of a hash would still be insignificant.


In reply to Re^5: SIG CHLD IGNORE and wait at same time by rjt
in thread SIG CHLD IGNORE and wait at same time by vsespb

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.