From owner-freebsd-questions Wed Jan 19 1:22:31 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 31E9315122 for ; Wed, 19 Jan 2000 01:22:27 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.9.3/8.9.3) id KAA01178; Wed, 19 Jan 2000 10:22:24 +0100 (CET) (envelope-from olli) Date: Wed, 19 Jan 2000 10:22:24 +0100 (CET) Message-Id: <200001190922.KAA01178@dorifer.heim3.tu-clausthal.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG Reply-To: freebsd-questions@FreeBSD.ORG Subject: Re: Detecting when your parent process dies. X-Newsgroups: list.freebsd-questions In-Reply-To: <863amm$271f$1@atlantis.rz.tu-clausthal.de> User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (FreeBSD/3.4-19991219-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Scott Hess wrote in list.freebsd-questions: > "Giorgos Keramidas" 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