how this program creates zombie process?

Vishwanath Dalvi picture Vishwanath Dalvi · Aug 11, 2011 · Viewed 7.3k times · Source

How the below program works and create a Zombie process under linux?

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main ()
{
  pid_t child_pid;

  child_pid = fork ();
  if (child_pid > 0) {
    sleep (60);
  }
  else {
    exit (0);
  }
  return 0;
}

Answer

AProgrammer picture AProgrammer · Aug 11, 2011

It creates children and doesn't wait (with one of the wait* system call) for them. And zombies are just that: children that the parents hasn't waited yet, the kernel has to maintain some information for them -- mainly the exit status -- in order to be able to return it to the parent.