zombie process?

zombie process?

Post by gar.. » Fri, 10 Mar 2000 04:00:00



Hi,

  Here is the code I use to handle signal SIGCHLD. Can anyone tell me why
there's still some zombie processes? I wonder the problem is caused by another
SIGCHLD signal occurs when the program is inside the signal handler. How to
prevent this or why there's zombie processes?(on FreeBSD3.3R)

  void chldhdlr(int signo)
  {
     int status;
     pid_t pid;

     pid = waitpid(-1, &status, WNOHANG);
  }

  main()
  {
     signal(SIGCHLD, &chldhdlr);
     /*daemon code here*/
  }

--Gareth

 
 
 

zombie process?

Post by Rainer Temm » Fri, 10 Mar 2000 04:00:00



>   Here is the code I use to handle signal SIGCHLD. Can anyone tell me why
> there's still some zombie processes? I wonder the problem is caused by
another
> SIGCHLD signal occurs when the program is inside the signal handler. How
to
> prevent this or why there's zombie processes?(on FreeBSD3.3R)

>   void chldhdlr(int signo)
>   {
>      int status;
>      pid_t pid;

>      pid = waitpid(-1, &status, WNOHANG);
>   }

>   main()
>   {
>      signal(SIGCHLD, &chldhdlr);
>      /*daemon code here*/
>   }

Hi Gareth,

you have to reinstall the signal-handler (call signal(SIGCHLD,chldhdlr);)
after you called waitpid() within your signal-handler.

Regards Rainer

 
 
 

zombie process?

Post by Hicna » Fri, 10 Mar 2000 04:00:00


Quote:>you have to reinstall the signal-handler (call signal(SIGCHLD,chldhdlr);)
>after you called waitpid() within your signal-handler.

or use "sigset", or "sigaction" instead of signal ;)

Regards
Hicnar

 
 
 

zombie process?

Post by Andrew Gabri » Fri, 10 Mar 2000 04:00:00




Quote:

>Hi,

>  Here is the code I use to handle signal SIGCHLD. Can anyone tell me why
>there's still some zombie processes? I wonder the problem is caused by another
>SIGCHLD signal occurs when the program is inside the signal handler. How to
>prevent this or why there's zombie processes?(on FreeBSD3.3R)

You don't necessarily see as may SIGCHLD's as you have dead children
waiting to be reaped, as SIGCHLD's are not queued up. Thus in your handler,
you need to reap all those which are currently outstanding, not just one.

Quote:>  void chldhdlr(int signo)
>  {
>     int status;
>     pid_t pid;

>     pid = waitpid(-1, &status, WNOHANG);
>  }

 void chldhdlr(int signo)
 {
    int status;
    pid_t pid;

    do
    {
       pid = waitpid(-1, &status, WNOHANG);
    }
    while (pid > 0);
 }

Quote:>  main()
>  {
>     signal(SIGCHLD, &chldhdlr);
>     /*daemon code here*/
>  }

Whilst I think signal() is safe on BSD (sorry, I can't remember for sure),
it would make your code clearer and more portable if you used sigaction()
instead. sigaction() is consistent across all unixs whereas signal() isn't.

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

zombie process?

Post by Andrew Giert » Fri, 10 Mar 2000 04:00:00


 gareth> Hi,

 gareth>   Here is the code I use to handle signal SIGCHLD. Can anyone
 gareth> tell me why there's still some zombie processes? I wonder the
 gareth> problem is caused by another SIGCHLD signal occurs when the
 gareth> program is inside the signal handler. How to prevent this or
 gareth> why there's zombie processes?(on FreeBSD3.3R)

Firstly, always use sigaction() to install signal handlers, not signal().

Secondly, you need to loop in the signal handler:

void chldhdlr(int signo)
{
    int status;
    pid_t pid;
    int saveerrno = errno;

    while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
        /* do whatever you want to do with PID and STATUS */;

    errno = saveerrno;

Quote:}

If you still see zombie processes that persist, then make sure you're
not blocking SIGCHLD inappropriately. (If you do anything in your
signal handler that accesses global data, then you need to block
SIGCHLD when you access that data in your main code, but make sure
that you're unblocking it correctly.)

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

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. nfs rw and ro access

3. Zombie processes

4. Need help with diald, PLEASE

5. KDE creating a zombie process

6. IPX Bridging

7. NIS creates zombie processes

8. how to change resolutions

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