Subject: Re: Zombie processes
To: None <netbsd-help@netbsd.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-help
Date: 04/17/2001 13:12:06
On Tue, 17 Apr 2001, Todd Vierling wrote:
> On Tue, 17 Apr 2001, Jeremy C. Reed wrote:
>
> : 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?
Thanks for the code and suggestions. I fixed my problem with:
(already had sys/types.h)
#include <sys/wait.h>
#include <signal.h>
void
child_signal_handler (int signal)
{
if (signal == SIGCHLD) {
int stat;
while (waitpid (-1, &stat, WNOHANG) > 0);
}
return;
}
and before my main loop:
signal (SIGCHLD, child_signal_handler);
Also, when I stopped my old (bad) version all the zombies disappeared. (I
guess init cleaned up.)
By the way, I am using execve() -- all the zombies were "sh".
argv[0] = "xterm";
argv[1] = "-e";
argv[2] = "lynx";
argv[3] = url;
argv[4] = 0;
if (execve("/usr/X11R6/bin/xterm", argv, environ)) {
I can't see in the execve(2) manual page any mention of starting a shell.
It seems like the zombie would be "xterm" (not "sh"). Is this because the
xterm is starting "sh"?
Jeremy C. Reed
http://www.reedmedia.net/