Thread: zombie analysis

  1. #1
    Registered User
    Join Date
    Sep 2005

    zombie analysis


    first i will post my code, then i say what happens when i start the program.

    int fork_service(service_t *s){
            int pid;
            pid = fork();
            if (pid == -1){
                    perror("ERRfork_service: ");
                    return -1;
            if (pid == 0){
                    // child
                    int ret;
                    if ((ret = execvp(s->path, s->flags)) == -1){
                            perror("ERRfork_service: "); //should never get here
                            //need to free allocations?
            return pid;
    ok i run this and look at the process table:

    #ps -ax
    9228 pts/5 S+ 0:00 ./a.out
    9232 pts/5 Z+ 0:00 [thttpd] <defunct>
    9233 ? Ss 0:00 /usr/sbin/thttpd -C /etc/thttpd/thttpd.conf


    #ps -ejH says that the zombie is a child of a.out, and the running thttpd process is a direct child of init.

    say if i am right with this:

    when thttpd starts it immediately forks a copy of its own, then the "original" thttpd exits, (...and becomes a zombie), and "init" inherits the thttpd child.

    now i am out of control of killing the process that i started at some time in the program, which originally was my plan...

    is the thttpd behavior like an often used strategy or so?

    thanks for any comments,


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It remains a zombie until you call one of these functions (from the parent process)

    #include <sys/types.h>
    #include <sys/wait.h>

    pid_t wait(int *status);
    pid_t waitpid(pid_t pid, int *status, int options);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2005
    thanks salem, i know that i need to call wait() ... but this is not the point of interest.

    just to mention, i resolve the child zombie thing by calling sigaction() and setting SA_NOCLDWAIT (only for 2.6 kernels)

    What i really find to be my problem is that I lose control of my child process.

    I need to find a way to kill my child and ALL of its descendants, even if my child has already exited and thus all its children got adopted by 'init'

    I read something about this might be possible using process groups.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Unreapable zombie
    By brewbuck in forum Linux Programming
    Replies: 5
    Last Post: 03-30-2009, 09:04 PM
  3. analysis and answers to ACM ICPC?
    By George2 in forum C Programming
    Replies: 0
    Last Post: 08-03-2006, 04:37 AM
  4. Dev-C++ Profile Analysis
    By Orborde in forum C++ Programming
    Replies: 0
    Last Post: 05-28-2005, 01:37 AM
  5. rhetorical analysis and why it is for YOU!
    By doubleanti in forum A Brief History of
    Replies: 2
    Last Post: 03-30-2003, 02:11 PM