I dont think I am understanding your problem now. What do you mean by a 'non-stopped parent'. I think you are saying that the parent 'do' loop never ends so it keeps printing? On my system everything worked beautifully. They parent looped until the child died, then the parent quit the loop and exited. What OS are you using, I am on an SGI irix machine, so there could be differences with the OS handleing of signals and forking. Anomolies in forking/signal handling can be hugely dependant on OS.

Did you try the signal handling example? Since this program is so short I would recommend stepping through the debugger (following the parent) to see what the results of your waitpid function is.

Maybe the waitpid does not return a -1 (it should when all children die. ... you are only forking once?). It should return a 0 when any child dies, so maybe change the logic to
do { ... code here ... } while $child_pid > 0;
This will loop until *any* child dies. (Well on my system it would anyway.)

Another idea (this might be completely false) maybe your child forks again? It might be that if the child process itself becomes a parent, then the grandparent waitpid might not return a -1. I have no idea ... something to consider though.

Hopes this helps. Reply if you get more info.

In reply to RE: Re: fork... by perlmonkey
in thread fork... by Anonymous Monk

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.