这个程序如何创建僵尸进程?

mr_*_*air 2 c linux process zombie-process

以下程序如何工作并在linux下创建一个Zombie进程?

#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;
}
Run Code Online (Sandbox Code Playgroud)

APr*_*mer 8

它会创建子项,而不会等待(使用wait*系统调用之一).僵尸就是这样:父母还没有等待的孩子,内核必须为他们维护一些信息 - 主要是退出状态 - 以便能够将其返回给父母.