Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jan 2000 10:22:24 +0100 (CET)
From:      Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Detecting when your parent process dies.
Message-ID:  <200001190922.KAA01178@dorifer.heim3.tu-clausthal.de>
In-Reply-To: <863amm$271f$1@atlantis.rz.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Scott Hess <scott@avantgo.com> wrote in list.freebsd-questions:
 > "Giorgos Keramidas" <charon@hades.hell.gr> wrote:
 >> On Mon, Jan 17, 2000 at 08:43:57AM -0800, Scott Hess wrote:
 >> | Is there any way for an rfork() process to detect if it's parent process
 >> | has died?  I mean via some sort of asynchronous notification?
 >>
 >> From the manpage of kill(2) we read:
 > 
 > kill( pid, 0) tells me, if I know to ask, "Is this process alive."
 > Unfortunately, the process I want to know that is going to be in a read(),
 > or perhaps a select().  I could arrange for it to poll for the parent
 > process death, but that's going to be fairly inefficient.

You're right, that would be inefficient and "ugly".

There is a better way:  You can arrange to open a pipe() or
socketpair() between the parent and the child process, and
include the file descriptor in your select() FD set (the one
checking for reading).

When the parent process dies, the pipe or socketpair is
closed, and the child's select() returns, telling you that
the file descriptor is ready for reading (which indicates
an EOF).

Regards
   Oliver

-- 
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)

"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
                                         (Terry Pratchett)


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001190922.KAA01178>