The child cannot wait for the parent. That is not how it works.

The child can, however, "divorce" itself from its parent and be adopted by init (process 1), as is stated in another part of this thread.

If you are getting a defunct process, either you are not waiting for your spawned process, or your program has grandchildren that the child process is not reaping.

When the process shows up as defunct in the process table, that process has finished, and the operating system is just keeping a data structure around with the exit information so that the parent process can read it if it cares. The parent process must deal with its children, either by waiting for it, informing perl / the os to ignore it (%SIG and perlipc), or exiting your program and letting the OS handle it.

It is said that "only perl can parse Perl." I don't even come close until my 3rd cup of coffee. --MidLifeXis


In reply to Re^3: Fork Causing <defunct> by MidLifeXis
in thread Fork Causing <defunct> by owen

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.