Subject: Re: Zombie processes
To: Jeremy C. Reed <reed@reedmedia.net>
From: Antti Kantee <pooka@iki.fi>
List: netbsd-help
Date: 04/17/2001 22:15:06
On Tue Apr 17 2001 at 12:07:33 -0700, Jeremy C. Reed wrote:
> On Tue, 17 Apr 2001, Antti Kantee wrote:
> 
> > Actually, if you kill a process's parent, it should be inherited by
> > init, which will wait() for the process once it dies and make the zombie
> > ``go away''.
> > 
> > You have some buggy programs which don't wait() for their children. Fix
> > them, or as a quick solution, kill the parent.
> 
> What if you don't want to wait() for it? For example, I have a little X
> app that when I click in it, it forks a new process and then execve()'s a
> browser (using the URL from the X copy buffer). (It creates a lot of
> zombies!) I want to wait() for it, but I don't want my parent application
> to stall until the child closes -- any code examples?

The classic method for not wanting to wait() is to fork twice if you can
manage the overhead. That way you don't have to wait for anything, since
the child processes will automagically be owned by init.

And if you want to wait for the process, you can use it to your
advantage that you get SIGCHLD delivered to the parent every time a
child dies.

See eg. Stevens' Advanced Programming in the Unix Environment for code
examples and much more.

-- 
Antti Kantee <pooka@iki.fi>          v          Of course he runs NetBSD
http://www.iki.fi/pooka/             i            http://www.NetBSD.org/