How can a child detect the death of its parent

Reuben Wachtfogel ruben at bcstec.boeing.com
Sat Jun 8 06:01:58 AEST 1991


In article <298 at wimpy.nms.gdc.portal.com>, bergquis at nms.gdc.portal.com (Brett Bergquist) writes:
> I have an application with forks a tightly coupled child process to handle
> communications functions.  The child communicates to the parent through
> a pipe.
> 
> I know how to detect the death of the child process using SIGCLD in the parent,
> but how can I detect the death of the parent process in the child?
> 

The parent could be set up to signal the child upon most non-violent
terminations with kill (e.g. use signal to trap termination faults)

Additionally the child could poll for the existence of the parent.
signal(SIGALRM, check_for_parent);
alarm(TEN_SECONDS);

where check_for_parent checks for getppid()==1
which means that the parent is gone and the child has
been adopted by the init (UID=1) process. 

I doubt this is very robust though, especially in cases where the
parent has zombied out, and I'll be checking here for a better answer.

----------------------------------------------------------------------
I have used something like this on APOLLO and it seems to work but
...

P.S. My recent posting containing site-specific article numbers
	 was intended to inspire people to REALLY read the FAQs. Thanx
	 to the many (!!) letters noting my goof. Please no more.



More information about the Comp.unix.questions mailing list