僵尸进程(zombie process )
来源:互联网 发布:查淘宝在线人数的插件 编辑:程序博客网 时间:2024/05/18 10:33
僵尸进程参照百度百科,及其部分论坛内容。
In UNIX System terminology, a process that has terminated,but whose parent has not yet waited for it, is called a zombie. 在UNIX 系统中,一个进程结束了,但是他的父进程没有等待(调用wait / waitpid)他, 那么他将变成一个僵尸进程。
如果该进程的父进程已经先结束,那么该进程就不会变成僵尸进程, 因为系统进程Init 会自动接管他,成为他的父进程。
僵尸进程(Zombie)可以认为只是一种数据结构,包括进程号the process ID,退出状态the termination status of the process,运行时间the amount of CPU time taken by the process等。进程结束时,内核释放该进程占用所有的资源,包括打开的文件,占用的内存等,但是唯独没有释放标识进程自身状态信息的结构(PCB),即僵尸进程。
僵尸进程产生的原因:
UNⅨ提供了一种机制可以保证只要父进程想知道子进程结束时的状态信息, 就可以得到。这种机制就是: 在每个进程退出的时候,内核释放该进程所有的资源,包括打开的文件,占用的内存等。但是仍然为其保留一定的信息(包括进程号the process ID,退出状态the termination status of the process,运行时间the amount of CPU time taken by the process等)。直到父进程通过wait / waitpid来取时才释放. 但这样就导致了问题,如果进程不调用wait / waitpid的话,那么保留的那段信息就不会释放,其进程号就会一直被占用,从而产生僵尸进程。
系统所能使用的进程号是有限的,如果大量的产生僵死进程,将因为没有可用的进程号而导致系统不能产生新的进程. 此即为僵尸进程的危害,应当避免。
注释:
SIGCHLD属于unix以及类unix系统的一种信号。
在一个进程终止或者停止时,将SIGCHLD信号发送给其父进程。按系统默认将忽略此信号。如果父进程希望被告知其子系统的这种状态,则应捕捉此信号。信号的捕捉函数中通常调用wait函数以取得进程ID和其终止状态。
备注:
kill
command has no effect on a zombie process.When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. The parent can read the child's exit status by executing the wait
system call, whereupon the zombie is removed. The wait
call may be executed in sequential code, but it is commonly executed in a handler for the SIGCHLD signal, which the parent receives whenever a child has died.
After the zombie is removed, its process identifier (PID) and entry in the process table can then be reused. However, if a parent fails to call wait
, the zombie will be left in the process table. In some situations this may be desirable, for example if the parent creates another child process it ensures that it will not be allocated the same PID. On modern UNIX-like systems (that comply with SUSv3 specification in this respect), the following special case applies: if the parent explicitly ignores SIGCHLD by setting its handler to SIG_IGN
(rather than simply ignoring the signal by default) or has the SA_NOCLDWAIT
flag set, all child exit status information will be discarded and no zombie processes will be left.
A zombie process is not the same as an orphan process. An orphan process is a process that is still executing, but whose parent has died. They do not become zombie processes; instead, they are adopted by init
(process ID 1), which wait
s on its children.
Zombies can be identified in the output from the Unix ps
command by the presence of a "Z
" in the "STAT" column.[1] Zombies that exist for more than a short period of time typically indicate a bug in the parent program, or just an uncommon decision to reap children (see example). If the parent program is no longer running, zombie processes typically indicate a bug in the operating system. As with other leaks, the presence of a few zombies is not worrisome in itself, but may indicate a problem that would grow serious under heavier loads. Since there is no memory allocated to zombie processes except for the process table entry itself, the primary concern with many zombies is not running out of memory, but rather running out of process ID numbers.
To remove zombies from a system, the SIGCHLD signal can be sent to the parent manually, using the kill
command. If the parent process still refuses to reap the zombie, the next step would be to remove the parent process. When a process loses its parent, init
becomes its new parent.Init
periodically executes the wait
system call to reap any zombies with init
as parent.
- 僵尸进程(zombie process)
- 僵尸进程(zombie process )
- 僵尸进程 (Zombie Process)
- 僵尸进程Zombie process
- Linux僵尸进程(Zombie process)
- 僵尸(zombie)进程
- 僵尸进程(Zombie)
- 僵尸进程(Zombie)
- reap linux zombie process 僵尸进程
- 避免产生僵尸进程的N种方法(zombie process)
- 僵尸进程zombie
- Linux Zombie 僵尸进程
- 什么是僵尸进程(zombie)?
- Linux 的僵尸(zombie)进程
- 如何察看僵尸进程 zombie
- Linux 的僵尸(zombie)进程
- Linux 的僵尸(zombie)进程
- Linux 的僵尸(zombie)进程
- vm 序列号
- 业界信息系统集成的三个主流模式:单点登录、数据融合、过程协同
- linux df命令详解
- String.valueOf(a)和(String)a有什么区别
- OVF Deployment Failed: File ds:///vmfs/volumes/uuid/_deviceImage-0.iso was not found
- 僵尸进程(zombie process )
- 网上回答网友的问题
- Linux cut命令详解
- MapObject2.1在C#中的运用
- VC编程调用dxdiag生成XML文件,来获取系统配置情况
- 数制转换
- C 语言文件操作一般过程
- C++采用递归算法寻找一个整型数组中的最大元素
- 浅谈 Sencha 2.0 中image和carousel的图片自适应大小的应用