Results 1 to 2 of 2

Thread: question regarding zombie process handover

  1. #1
    Join Date
    Aug 2012
    Beans
    533

    question regarding zombie process handover

    I was reading up about zombie process and I did this piece of code to create one.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
     pid_t pid;
    
     pid = fork();
    
     /* parent */
     if(pid)
     {
      sleep(60);
     }
     /* child */
     else
     {
       printf("I'm the child\n");
       exit(0);
     }
    }
    I executed this and on another terminal I was watching the ps output. I could see that for those 60 seconds, the above executable was a zombie, as in, I was getting a.out<defunct>. All good!

    But my question is, after 60 seconds,the executable is no longer a zombie process. So who moves it out of the process table, the parent itself or 'init' ?(Note : my parent process is not using 'wait')

    Please advise.
    Thanks

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    1,795
    Distro
    Kubuntu 12.10 Quantal Quetzal

    Re: question regarding zombie process handover

    The "zombie" state means that the parent hasn't yet collected the result from the child (the process is no longer active but its control structure is kept around in case the parent needs them). So you see the child process as zombie when the parent sleeps. But when the parent exits after waking up from its one-minute sleep, this exits kills all ist child processes whatever their states (running or zombie)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •