zombie analysis

This is a discussion on zombie analysis within the Linux Programming forums, part of the Platform Specific Boards category; Hey, first i will post my code, then i say what happens when i start the program. Code: int fork_service(service_t ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    16

    zombie analysis

    Hey,

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

    Code:
    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?
                            exit(EXIT_FAILURE);
                    }
            }
            //parent;
            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
    ...

    and

    #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,

    felix

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,591
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    16
    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 Cprogramming.com
    Replies: 2
    Last Post: 03-30-2003, 01:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21