You don't have to save $$, just use getppid() and wait for it to go to 1 (assuming a fairly Unix-like system).

waitpid only works on children.

The only way I can think that might get the OS to send an asynchronous event (aka signal) to the child when the parent dies is to make the parent the head of a process group. But I don't have my process group docs handy (sorry).

If you use select, then you don't need to use alarm. But either of these is probably a good choice.

Also, you can also try to get the parent to trap that it is about to exit and notify the child any way you like. You can use END and signal handlers in the parent for this.

For extreme cases, you can have a grandparent who's only purpose is to wait for the parent to die. But combining the above options can give you immediate notification for orderly parent death and reasonably quick detection for unorderly parent death.


In reply to Re: Checking up on your parents by tye
in thread Checking up on your parents by $ENV{REMOTE_USER}

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.