[英]can't create zombie process in linux
Well I have weird problem. 好吧,我有一个奇怪的问题。 I can't create a zombie process in my project, but I can do this in other file.
我无法在我的项目中创建僵尸进程,但我可以在其他文件中执行此操作。 There's simple instructions:
有简单的说明:
int main()
{
if(fork()==0)
printf("Some instructions\n");
else
{
sleep(10);
wait(0);
}
return 0;
}
That simple code create a zombie process for 10 seconds. 这个简单的代码创建了一个10秒的僵尸进程。 I'm checking and it actually exists.
我正在检查,它确实存在。
But if I copy this code to my program (my own shell), everything executing like before BUT zombie process doesn't exist at all. 但是,如果我将此代码复制到我的程序(我自己的shell)中,那么在BUT僵尸进程之前执行的所有操作都根本不存在。 I don't know what's the difference.
我不知道有什么区别。 It's same code.
这是相同的代码。
Is there a more information I should know about that? 有更多的信息我应该知道吗? Is there a other way to create zombie in simple way?
有没有其他方法以简单的方式创建僵尸?
Try this python script: 试试这个python脚本:
#!/usr/bin/python
# -*- coding: utf8 -*-
import subprocess
import time
import threading
# Create 100 subprocesses
proc = {}
for i in xrange(0,1000):
proc[i] = subprocess.Popen(['ls','-l'])
# create zombies from this processes, observe one minute zombies
time.sleep(60)
# Zombies dead
proc.communicate()
time.sleep(5)
Thereafter check zombies: 此后检查僵尸:
# ps -A | grep defunc
14711 pts/49 00:00:00 ls <defunct>
14713 pts/49 00:00:00 ls <defunct>
14716 pts/49 00:00:00 ls <defunct>
....
14740 pts/49 00:00:00 ls <defunct>
14741 pts/49 00:00:00 ls <defunct>
14742 pts/49 00:00:00 ls <defunct>
14743 pts/49 00:00:00 ls <defunct>
14746 pts/49 00:00:00 ls <defunct>
14749 pts/49 00:00:00 ls <defunct>
....
14805 pts/49 00:00:00 ls <defunct>
14806 pts/49 00:00:00 ls <defunct>
Or C: 或者C:
#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;
}
Should work like a charm, like a crystal clear pure Haitian Vodou . 应该像魅力一样工作,就像水晶般清澈纯净的海天Vodou 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.