Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.unix.wizards Subject: Re: How can a parent find out if one of its children is still alive Message-ID: Date: 6 Jun 90 23:11:14 GMT References: <30408@cup.portal.com> <6334@ozdaltx.UUCP> <1046@gargoyle.uchicago.edu> <13071@ulysses.att.com> Sender: news@OSF.ORG Distribution: na Organization: Open Software Foundation Lines: 44 In-reply-to: smb@ulysses.att.com's message of 6 Jun 90 19:22:28 GMT In article <13071@ulysses.att.com> smb@ulysses.att.com (Steven Bellovin) writes: | Path: paperboy!think!snorkelwacker!usc!ucsd!ucbvax!ulysses!ulysses.att.com!smb | From: smb@ulysses.att.com (Steven Bellovin) | Newsgroups: comp.unix.wizards | Date: 6 Jun 90 19:22:28 GMT | References: <30408@cup.portal.com> <6334@ozdaltx.UUCP> <1046@gargoyle.uchicago.edu> | Sender: netnews@ulysses.att.com | Distribution: na | Lines: 15 | | In article <1046@gargoyle.uchicago.edu>, matt@group-w.uchicago.edu (Matt Crawford) writes: | } ) DeadHead@cup.portal.com (Bruce M Ong) writes: | } ) > How can a parent find out if one of its children is still alive | } ) > or not without | } | } Tom Armistead, wizard-wannabe, answers: | } ) i.e.: if( kill( child_pid, 0 ) == -1 ) | } ) puts( "The child is dead" ); | } | } overlooking the possibility that the child exited many minutes ago and | } the pid is now being used by some unrelated process. | | You can look at errno to determine if the kill() failed because of | a uid mismatch. That will yield a lot of info if root isn't doing | the checking. Unless of course, the newly created pid is running one of your cron jobs, a different job created by your job control shell, on a different window owned by you, or somebody running nethack which is setuid to your account. Kill only checks for the effective UID being the same. The above methods are ways there can be a process with the same PID as a dearly departed child process, and have the same EUID as the parent proces, but not be the process the parent wants to deal with. I'm sure I've missed a few ways to create such processes. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so