*BSD News Article 96796


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.netspace.net.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!news.maxwell.syr.edu!news.apfel.de!univ-lyon1.fr!pasteur.fr!jussieu.fr!eurocontrol.fr!polaris.eurocontrol.fr!not-for-mail
From: Herve Couppe de Lahongrais - CDL <cdl@eurocontrol.fr>
Newsgroups: comp.unix.programmer,comp.unix.sco.misc,comp.unix.bsd.freebsd.misc
Subject: Re: How to Clean up an Orphan Process in HP-UX?
Date: Tue, 03 Jun 1997 11:25:43 +0200
Organization: Eurocontrol Experimental Centre, Bretigny-Sur-Orge, France
Lines: 42
Message-ID: <3393E317.2C9A@eurocontrol.fr>
References: <865300017.24837@dejanews.com>
NNTP-Posting-Host: berlioz.eurocontrol.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.0 (X11; I; HP-UX A.09.05 9000/755)
Xref: euryale.cc.adfa.oz.au comp.unix.programmer:55145 comp.unix.sco.misc:41866 comp.unix.bsd.freebsd.misc:42118

cheng@consilium.com wrote:
> 
> Hi,
> 
> Suppose we have a process, and it forks a child process, in HP-UX 10.0.
> If the parent terminates (in an unexpected way), we may want to let that
> orphan child process exit.  How can this be implemented?  Or in other
> words, how can the child process know its parent has terminated?  (It
> seems signal SIGHUP doesn't work.)
> 
> Thanks.

If the parent process terminates before the child process, then the
child process becomes a child of the "init" process (PID=1). The child
process may know if its parent has terminated by calling the function
"kill" with the "sig" parameter set to 0, but first it will have to keep
the PID of its parent process. For example :

#include <errno.h>
#include <signal.h>
#include <unistd.h>

static pid_t parent_pid;

...
parent_pid = getppid();
...
if (kill(parent_pid, 0) < 0) {
	if (errno == ESRCH) {
		/*
		** The parent process has terminated
		*/
		...
	} else {
		/*
		** Other errors
		*/
		...
	}
-- 
Herve Couppe de Lahongrais (SEU)       | Eurocontrol Experimental Centre
mailto:cdl@eurocontrol.fr              | France