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.
|