Creating a Zombie Process Using the kill Function

I am trying to create a zombie process using a function kill, but it just kills the child and returns 0.

int main ()
{
  pid_t child_pid;

  child_pid = fork ();

  if (child_pid > 0) {
    kill(getpid(),SIGKILL);
  }
  else {
    exit (0);
  }

  return 0;
}

When I check the status of the process, there is no status in the column z.

+4
source share
1 answer

Here is a simple recipe that a zombie should create:

#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int main()
{
    int pid = fork();
    if(pid == 0) {
        /* child */
        while(1) pause();
    } else {
        /* parent */
        sleep(1);
        kill(pid, SIGKILL);
        printf("pid %d should be a zombie\n", pid);
        while(1) pause();
    }
}

The key is that the parent element, that is, this program, continues to work, but does not execute wait()on a dying child.

- , . , . , - - (, init), , , , .

, , , - . Unix , , . Unix , , , wait.

, : Unix , .

+3

All Articles