Zombie processes

Zombie processes

Post by johnv.. » Thu, 23 Mar 2000 04:00:00



Hi,

I have a question about zombies. My book says you should get rid of
zombies like this when calling fork():

int n, p;
n=fork();
...
if (n==0)  {
 /*do child stuff*/

Quote:}

else if (n > 0) {
 /*do parent stuff*/
 wait(&p);

Quote:}

And that this should kill any zombies. Is that correct? And why do some
people ignore SIG_CHLD like this:

signal(SIG_CHLD, SIG_IGN);

in programs that call fork()? Why ignore SIG_CHLD? When does a program
recieve a SIG_CHLD, and does that cause a process to be a zombie?

Thanks,
 -- John

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Zombie processes

Post by stanislav shaluno » Thu, 23 Mar 2000 04:00:00



> int n, p;
> n=fork();
> ...
> if (n==0)  {
>  /*do child stuff*/
> }
> else if (n > 0) {
>  /*do parent stuff*/
>  wait(&p);
> }

> And that this should kill any zombies. Is that correct?

Almost.  If you have many children, you won't know which one has just
exited.  [And "kill" isn't a word you would use for zombies, because
they're, uh, already dead.  Many people say "reap off" or "get rid
of."]

Quote:> And why do some people ignore SIG_CHLD

Ignoring SIGCHLD is an old obscure non-portable way to reap off
zombies automatically.

It's better to install a handler for SIGCHLD that waits.
See FAQ for code.

 
 
 

Zombie processes

Post by Chris Wareha » Thu, 23 Mar 2000 04:00:00



> I have a question about zombies. My book says you should get rid of
> zombies like this when calling fork():

> int n, p;
> n=fork();
> ...
> if (n==0)  {
>  /*do child stuff*/
> }
> else if (n > 0) {
>  /*do parent stuff*/
>  wait(&p);
> }

> And that this should kill any zombies. Is that correct?

If the parent doesn't call wait(), then a terminating child process will have
it's exit status stored by the kernel until either the parent terminates or
calls wait(). This wastes resources, so it is generally best to call wait()
in the parent after the fork(). If you don't want to wait(), then a neat
trick is to call fork() from the child and have the first child terminate.
This means that the second child has no parent PID. It is then 'adopted'
by init, and no zombie is created when the child terminates. The original
parent simply has to wait() for the first child, which returns almost
immediately as it just fork()'s and exit()'s.

Quote:

> And why do some people ignore SIG_CHLD like this:

> signal(SIG_CHLD, SIG_IGN);

> in programs that call fork()? Why ignore SIG_CHLD? When does a program
> recieve a SIG_CHLD, and does that cause a process to be a zombie?

Ignoring SIGCHLD, which is the signal generated when a child dies, implies
that the parent is not interested in the exit status of it's children.
Therefore the kernel doesn't bother storing the status - and no zombies
are created for that process.

Chris

 
 
 

1. Zombie processes "owned" by apache processes ...

Morning all...

        I've searched just about everywhere I can think of, and either I'm
seeing the answer, but mis-reading it, or it hasn't quite been asked
this way before...

        I have an Apache 1.3.9 server running under FreeBSD 3.3-STABLE ...
all works well, except that, over time, I get alot of zombie processes
that look like:

USER       PID  PPID STAT  TT       TIME COMMAND
wwwadmin 11551 11012 Z     ??    0:00.00  (sh)
wwwadmin 11752 11012 Z     ??    0:00.00  (sh)
wwwadmin 12379 11012 Z     ??    0:00.00  (sh)    
wwwadmin 12661 11012 Z     ??    0:00.00  (sh)    
wwwadmin 12899 11012 Z     ??    0:00.00  (sh)    
wwwadmin 11012 11012 S     ??    0:02.20 /usr/local/sbin/apache

        If I kill off PID 11012, the (sh) zombies will follow ...

        The server uses SSI alot, calling perl processes.  My first guess
is that each time a .html contains a SSI, it has to call a shell to run the
perl command to get the output, which explains the 'sh's...but, if my guess
is correct, why is it leaving a zombie behind afterwards?

        Can anyone suggestion where to look further on this?  I've checked
the Apache bugs database, and a few "list archives" for apache that I could
find, but everything appears to be either unrelated or old...

Thanks for any insight/direction provided ...

--

Senior Systems Administrator                            Acadia University

  "These are my opinions, which are not necessarily shared by my employer"

2. Bttv errors with onboard video.

3. Zombie processes

4. FAQ for linux

5. KDE creating a zombie process

6. Is CardBus not supported at all in FBSD4.4?

7. NIS creates zombie processes

8. Forgot my root password - curious how to recover it from console. v2.6

9. Zombie Process - Debugging

10. Zombie processes ....

11. How to kill zombie processes

12. Q:how to avoid zombie processes?

13. Zombie processes and daemons under linux: need info how to write