百科网

首页 > 科技数码

科技数码

教你linux系统如何清理和避免僵尸进程

科技数码佚名2023-01-18

linux 如何清理僵尸进程?一些朋友在维护服务器的时候,发现有5个nova-novncproxy的僵尸进程,面对这些僵尸进程,我们该如何应对呢?其实也不难,下面小编教大家查杀和避免僵尸进程。

0126327 ? S 0:05 _ /usr/bin/python /usr/bin/nova-novncproxy --config-file=/etc/nova/nova.conf024765 ? Z 0:00 _ [nova-novncproxy] 034766 ? Z 0:00 _ [nova-novncproxy] 044767 ? Z 0:00 _ [nova-novncproxy] 054768 ? Z 0:00 _ [nova-novncproxy] 064769 ? Z 0:00 _ [nova-novncproxy] 复制代码26327 ? S 0:05 _ /usr/bin/python /usr/bin/nova-novncproxy --config-file=/etc/nova/nova.conf4765 ? Z 0:00 _ [nova-novncproxy] 4766 ? Z 0:00 _ [nova-novncproxy] 4767 ? Z 0:00 _ [nova-novncproxy] 4768 ? Z 0:00 _ [nova-novncproxy] 4769 ? Z 0:00 _ [nova-novncproxy]

定义:

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)他, 那么他将变成一个僵尸进程。 在fork()/execve()过程中,假设子进程结束时父进程仍存在,而父进程fork()之前既没安装SIGCHLD信号处理函数调用 waitpid()等待子进程结束,又没有显式忽略该信号,则子进程成为僵尸进程。

如何查看linux系统上的僵尸进程,如何统计有多少僵尸进程?

01#ps -ef | grep defunct复制代码#ps -ef | grep defunct

或者查找状态为Z的进程,Z就是代表zombie process,僵尸进程的意思。

另外使用top命令查看时有一栏为S,如果状态为Z说明它就是僵尸进程。

01Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie复制代码Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie

top命令中也统计了僵尸进程。或者使用下面的命令:

01ps -ef | grep defunct | grep -v grep | wc -l复制代码ps -ef | grep defunct | grep -v grep | wc -l

如何杀死僵尸进程呢?