Do you know what that next; is doing? Nothing. It's exiting a block you'd be exiting anyway.

As for the loop waiting for waitpid to return something other than 0, my first guess is, since "doesn't work" is kind of vague, that it seems to you the loop never runs?

Update:Yeah, what kennethk said abut it being a blocking call. I didn't even think of that for some reason. I'm going to blame lack of sleep. That explains the same loop-never-seems-to-run behavior but for the correct reason. I'll put my bad guess in a readmore. That's easier to read than a strikethrough.

If the loop seems like it never runs, it's probably because your child finishes its work and exits rather more quickly than you expected. If the child exits before you ever wait for it, you'll immediately get a nonzero return from waitpid(). Try doing what you need to do in the parent once right after the fork before you perform the loop, and see if that helps.

If you're having some other version of "doesn't work", then more detail may be helpful.


In reply to Re: Perl Forking : perform some action until child process dies by mr_mischief
in thread Perl Forking : perform some action until child process dies by robrt

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.