僵尸进程产生的原因¶
在 unix 或 unix-like
的系统中,当一个子进程退出后,它就会变成一个僵尸进程,如果父进程没有通过
wait
系统调用来读取这个子进程的退出状态的话,这个子进程就会一直维持僵尸进程状态。
On Unix and Unix-like computer operating systems, a zombie process
or defunct process is a process that has completed execution (via
the exit system call) but still has an entry in the process table:
it is a process in the "Terminated state". This occurs for child
processes, where the entry is still needed to allow the parent
process to read its child's exit status: once the exit status is
read via the wait system call, the zombie's entry is removed from
the process table and it is said to be "reaped". A child process
always first becomes a zombie before being removed from the resource
table. In most cases, under normal system operation zombies are
immediately waited on by their parent and then reaped by the system
– processes that stay zombies for a long time are generally an error
and cause a resource leak.
并且僵尸进程无法通过 kill 命令来清除。
本文将探讨如何手动制造一个僵尸进程以及清除僵尸进程的办法。