僵尸进程如何体现自己?
答
steenhulthin是正确的,但直到它被移动,有人可能会在这里回答它。僵尸进程存在于子进程终止的时间与父节点调用wait()
函数之一以获取其退出状态的时间之间。
一个简单的例子:
/* Simple example that creates a zombie process. */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void)
{
pid_t cpid;
char s[4];
int status;
cpid = fork();
if (cpid == -1) {
puts("Whoops, no child process, bye.");
return 1;
}
if (cpid == 0) {
puts("Child process says 'goodbye cruel world.'");
return 0;
}
puts("Parent process now cruelly lets its child exist as\n"
"a zombie until the user presses enter.\n"
"Run 'ps aux | grep mkzombie' in another window to\n"
"see the zombie.");
fgets(s, sizeof(s), stdin);
wait(&status);
return 0;
}
+3
+1的可能“残酷地让它的孩子存在......“:)和一个很好的答案。 –
好问题,但我认为它会更适合于http://unix.stackexchange.com/或http://askubuntu.com/ – steenhulthin