试试这个 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)
此后检查僵尸:
# 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>
或 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;
}
应该像魅力一样工作,像水晶般清澈纯净的海天巫毒。