僵尸进程概念

僵尸进程(Zombie process)通俗来说指那些虽然已经终止的进程,但仍然保留一些信息,等待其父进程为其收尸. 书面形式一点:一个进程结束了,但是他的父进程没有等待(调用wait / waitpid)他,那么他将变成一个僵尸进程。通过ps命令查看其带有defunct的标志。僵尸进程是一个早已死亡的进程,但在进程表(processs table)中仍占了一个位置(slot)。

  但是如果该进程的父进程已经先结束了,那么该进程就不会变成僵尸进程。因为每个进程结束的时候,系统都会扫描当前系统中所运行的所有进程,看看有没有哪个进程是刚刚结束的这个进程的子进程,如果是的话,就由Init进程来接管他,成为他的父进程,从而保证每个进程都会有一个父进程。而Init进程会自动wait其子进程,因此被Init接管的所有进程都不会变成僵尸进程

与ZOMBIE对应的进程状态还有RUNNING(正在运行或等待运行状态),UNINTERRUPTABLE(不可中断阻塞状态),INTERRUPTABLE(可中断阻塞状态),STOPPED(挂起状态)等。

关于僵尸进程的维基百科介绍:

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.

The term zombie process derives from the common definition of zombie — an undead person. In the term's metaphor, the child process has "died" but has not yet been "reaped". Also, unlike normal processes, the kill command has no effect on a zombie process.

Zombie processes should not be confused with orphan processes: an orphan process is a process that is still executing, but whose parent has died. These do not remain as zombie processes; instead, (like all orphaned processes) they are adopted by init (process ID 1), which waits on its children. The result is that a process that is both a zombie and an orphan will be reaped automatically.

僵尸进程查看

 

查看系统里面有那些僵尸进程,有很多方法,例如top命令,ps命令等

另外,使用ps和grep命令结合也能查看僵尸进程,当然有非常多的形式,如下所。

[root@mylnx01 ~]# ps aux | grep Zs |  grep -v grep

oracle    2002  0.0  0.0      0     0 ?        Zs   02:44   0:00 [sh] <defunct>

oracle    2013  0.0  0.0      0     0 ?        Zs   02:46   0:00 [sh] <defunct>

[root@mylnx01 ~]# 

 

 

[root@mylnx01 ~]# ps -ef | grep defunct

oracle    2002  4788  0 02:44 ?        00:00:00 [sh] <defunct>

oracle    2013  4788  0 02:46 ?        00:00:00 [sh] <defunct>

[root@mylnx01 ~]# 

 

[root@mylnx01 ~]# ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'

Zs    4788  2002 [sh] <defunct>

Zs    4788  2013 [sh] <defunct>

[root@mylnx01 ~]# 

查看僵尸进程的个数命令

[root@mylnx01 ~]# ps -ef | grep defunct | grep -v grep | wc -l

 

2

 

 

僵尸进程查杀

僵尸进程的查杀有时候是一个头痛的问题,僵尸进程有时候很杀不掉,有时候还不能乱杀。

要杀掉僵尸进程,一般有两个方法:

1:找到该defunct僵尸进程的父进程,将该进程的父进程杀掉,则此defunct进程将自动消失

2:重启服务器。

查看僵尸进程并杀掉

ps -ef | grep defunct | grep -v grep | awk {print "kill -9 " $2,$3}

一般情况下,不建议莽撞的kill掉这些僵尸进程,还是检查一下具体原因后,根据具体情况再做查杀,如下所示。

[root@mylnx01 ~]# ps -ef | grep defunct

oracle    2002  4788  0 02:44 ?        00:00:00 [sh] <defunct>

oracle    2013  4788  0 02:46 ?        00:00:00 [sh] <defunct>

root     12348 10441  0 12:18 pts/11   00:00:00 grep defunct

[root@mylnx01 ~]# cat /proc/2002/stack

[<ffffffff8105b9f5>] do_exit+0x67d/0x696

[<ffffffff8105baae>] sys_exit_group+0x0/0x1b

[<ffffffff8105bac5>] sys_exit_group+0x17/0x1b

[<ffffffff81011db2>] system_call_fastpath+0x16/0x1b

[<ffffffffffffffff>] 0xffffffffffffffff

[root@mylnx01 ~]# cat /proc/2013/stack

[<ffffffff8105b9f5>] do_exit+0x67d/0x696

[<ffffffff8105baae>] sys_exit_group+0x0/0x1b

[<ffffffff8105bac5>] sys_exit_group+0x17/0x1b

[<ffffffff81011db2>] system_call_fastpath+0x16/0x1b

[<ffffffffffffffff>] 0xffffffffffffffff

[root@mylnx01 ~]# cat /proc/4788/stack

[<ffffffff811de86e>] sys_semtimedop+0x68b/0x7e7

[<ffffffff81011db2>] system_call_fastpath+0x16/0x1b

[<ffffffffffffffff>] 0xffffffffffffffff

[root@mylnx01 ~]# 

[root@mylnx01 ~]# lsof -p 4788

COMMAND  PID   USER   FD   TYPE DEVICE      SIZE     NODE NAME

oracle  4788 oracle  cwd    DIR  253,6      4096  7880901 /u01/app/oracle/product/10.2.0/db_1/dbs

oracle  4788 oracle  rtd    DIR  253,0      4096        2 /

oracle  4788 oracle  txt    REG  253,6 104559054  7884256 /u01/app/oracle/product/10.2.0/db_1/bin/oracle

oracle  4788 oracle  DEL    REG    0,4            3211268 /SYSVdf6790e8

oracle  4788 oracle  mem    REG  253,0    143600  8421721 /lib64/ld-2.5.so

oracle  4788 oracle  mem    REG  253,0   1722304  8421722 /lib64/libc-2.5.so

oracle  4788 oracle  mem    REG  253,0    615136  8421739 /lib64/libm-2.5.so

oracle  4788 oracle  mem    REG  253,0     23360  8421607 /lib64/libdl-2.5.so

oracle  4788 oracle  mem    REG  253,0    145824  8421724 /lib64/libpthread-2.5.so

oracle  4788 oracle  mem    REG  253,0    114352  8421738 /lib64/libnsl-2.5.so

oracle  4788 oracle  mem    REG  253,0     53880  8421403 /lib64/libnss_files-2.5.so

oracle  4788 oracle  mem    CHR    1,5               4603 /dev/zero

oracle  4788 oracle  mem    REG  253,0      3768 10426606 /usr/lib64/libaio.so.1.0.1

oracle  4788 oracle  mem    REG  253,6      1552  7893073 /u01/app/oracle/product/10.2.0/db_1/dbs/hc_epps.dat

oracle  4788 oracle  mem    REG  253,6   3796601  7888182 /u01/app/oracle/product/10.2.0/db_1/lib/libnnz10.so

oracle  4788 oracle  mem    REG  253,6    123345  7885115 /u01/app/oracle/product/10.2.0/db_1/lib/libdbcfg10.so

oracle  4788 oracle  mem    REG  253,6     64041  7887888 /u01/app/oracle/product/10.2.0/db_1/lib/libclsra10.so

oracle  4788 oracle  mem    REG  253,6  11385162  7883147 /u01/app/oracle/product/10.2.0/db_1/lib/libjox10.so

oracle  4788 oracle  mem    REG  253,6    516097  7887854 /u01/app/oracle/product/10.2.0/db_1/lib/libocrutl10.so

oracle  4788 oracle  mem    REG  253,6    691049  7887853 /u01/app/oracle/product/10.2.0/db_1/lib/libocrb10.so

oracle  4788 oracle  mem    REG  253,6    681761  7887852 /u01/app/oracle/product/10.2.0/db_1/lib/libocr10.so

oracle  4788 oracle  mem    REG  253,6      8545  7885226 /u01/app/oracle/product/10.2.0/db_1/lib/libskgxn2.so

oracle  4788 oracle  mem    REG  253,6   1772385  7887887 /u01/app/oracle/product/10.2.0/db_1/lib/libhasgen10.so

oracle  4788 oracle  mem    REG  253,6    177809  7884216 /u01/app/oracle/product/10.2.0/db_1/lib/libskgxp10.so

oracle  4788 oracle    0r   CHR    1,3               4601 /dev/null

oracle  4788 oracle    1r   CHR    1,3               4601 /dev/null

oracle  4788 oracle    2w   REG  253,6      1447  7995467 /u01/app/oracle/admin/epps/bdump/epps_psp0_4788.trc

oracle  4788 oracle    3r   CHR    1,3               4601 /dev/null

oracle  4788 oracle    4r   CHR    1,3               4601 /dev/null

oracle  4788 oracle    5w   REG  253,6       663  1638412 /u01/app/oracle/admin/epps/udump/epps_ora_4784.trc (deleted)

oracle  4788 oracle    6w   REG  253,6     30440  7995465 /u01/app/oracle/admin/epps/bdump/alert_epps.log.20150904 (deleted)

oracle  4788 oracle    7u   REG  253,6         0  6930433 /u01/app/oracle/product/10.2.0/db_1/dbs/lkinstepps (deleted)

oracle  4788 oracle    8w   REG  253,6     30440  7995465 /u01/app/oracle/admin/epps/bdump/alert_epps.log.20150904 (deleted)

oracle  4788 oracle    9u   REG  253,6      1552  7893073 /u01/app/oracle/product/10.2.0/db_1/dbs/hc_epps.dat

oracle  4788 oracle   10r   CHR    1,5               4603 /dev/zero

oracle  4788 oracle   11r   REG  253,6    849408  7887921 /u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb

oracle  4788 oracle   12r   CHR    1,5               4603 /dev/zero

oracle  4788 oracle   13u   REG  253,6      1552  7893073 /u01/app/oracle/product/10.2.0/db_1/dbs/hc_epps.dat

oracle  4788 oracle   14uR  REG  253,6        24  7893074 /u01/app/oracle/product/10.2.0/db_1/dbs/lkEPPS

oracle  4788 oracle   15r   REG  253,6    849408  7887921 /u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb

查看僵尸进程的父进程,发现是对应的是ORACLE里面PSPO进程,关于这个进程,我也没有把握是否可以KIll掉。所以选择重启服务器比较保险一点。

参考资料:

https://en.wikipedia.org/wiki/Zombie_process

http://linux.alai.net/viewblog.php?id=48189

Linux 僵尸进程查杀的更多相关文章

  1. Linux 僵尸进程的筛选和查杀

    一.筛选 ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' 二.查杀 ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' ...

  2. Unix/Linux僵尸进程

    1. 僵尸进程的产生: 一个进程调用exit命令结束自己生命的时候,其实它并没有真正的被销毁,而是留下一个称为“僵尸进程”的数据结构.这时它已经放弃了几乎所有内存空间,没有任何可执行代码,也不能被调度 ...

  3. linux僵尸进程

    什么是僵尸进程?    在UNIX 系统中,一个进程结束了,但是他的父进程没有等待(调用wait / waitpid)他, 那么他将变成一个僵尸进程.  在fork()/execve()过程中,假设子 ...

  4. Linux 僵尸进程

    Linux 允许进程查询内核以获得其父进程的 PID,或者其任何子进程的执行状态.例如,进程可以创建一个子进程来执行特定的任务,然后调用诸如 wait() 这样的一些库函数检查子进程是否终止.如果子进 ...

  5. 转载 linux 僵尸进程,讲的很透彻

    僵尸进程的产生和避免,以及wait,waitpid的使用 在fork()/execve()过程中,假设子进程结束时父进程仍存在,而父进程fork()之前既没安装SIGCHLD信号处理函数调用waitp ...

  6. Linux 僵尸进程如何处理

    Linux 允许进程查询内核以获得其父进程的 PID,或者其任何子进程的执行状态.例如,进程可以创建一个子进程来执行特定的任务,然后调用诸如 wait() 这样的一些库函数检查子进程是否终止.如果子进 ...

  7. linux僵尸进程产生的原因以及如何避免产生僵尸进程

    给进程设置僵尸状态的目的是维护子进程的信息,以便父进程在以后某个时间获取.这些信息包括子进程的进程ID.终止状态以及资源利用信息(CPU时间,内存使用量等等).如果一个进程终止,而该进程有子进程处于僵 ...

  8. linux一行命令查杀进程

    https://blog.csdn.net/primeprime/article/details/52415273 ps -efww | grep -w 'helloworld' | grep -v ...

  9. 记一次Linux服务器上查杀木马经历

    开篇前言 Linux服务器一直给我们的印象是安全.稳定.可靠,性能卓越.由于一来Linux本身的安全机制,Linux上的病毒.木马较少,二则由于宣称Linux是最安全的操作系统,导致很多人对Linux ...

随机推荐

  1. 走进异步世界-犯傻也值得分享:ConfigureAwait(false)使用经验分享

    在上周解决“博客程序异步化改造之后遭遇的性能问题”的过程中,我们干了一件自以为很有成就感的事——在表现层(MVC与WebForms)将所有使用await的地方都加上了ConfigureAwait(fa ...

  2. 使用MySQL WorkBench导出数据库

    1. 在MySQL WorkBench的Server Administrator中双击要连接的数据库: 2. 点击左边的Data Export,在右边的数据库列表中选择要导出的数据库: 3. Expo ...

  3. mysql int(3)与int(11)的区别

    总结,int(M) zerofill,加上zerofill后M才表现出有点点效果,比如 int(3) zerofill,你插入到数据库里的是10,则实际插入为010,也就是在前面补充加了一个0.如果i ...

  4. sina sae开发中出现的问题

    都是些小问题,但既然出现了,下次就该避免! 网站加载速度慢: 1.安装 Disable Google Fonts 字体插件即可  2.删代码 http://jingyan.baidu.com/arti ...

  5. 你知道url中的特殊符号含义么

    1.# #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如,http://www.example.com/index.html#print就代表网页index.html的print位置.浏 ...

  6. Javascript——闭包、作用域链

    1.闭包:是指有权访问另一个函数作用域中的变量的函数.创建闭包的常见方式:在一个函数内部创建另一个函数. function f(name){ return function(object){ var ...

  7. ErrorExecution failed for task 'apptransformClassesWithDexForDebug'

    [原因]: 在工程中既有本地的lib.jar文件,又有compile链接.

  8. C#实现jQuery的方法连缀

    jQuery的方法连缀使用起来非常方便,可以简化语句,让代码变得清晰简洁.那C#的类方法能不能也实现类似的功能呢?基于这样的疑惑,研究了一下jQuery的源代码,发现就是需要方法连缀的函数方法最后返回 ...

  9. MySQL之MySQL常用的函数方法

    MySQL常用函数 本篇主要总结了一些在使用MySQL数据库中常用的函数,本篇大部分都是以实例作为讲解,如果有什么建议或者意见欢迎前来打扰. limit Select * from table ord ...

  10. 安卓 9.png 图片的制作

    安卓的九宫格png图片可以自定义拉伸的区域,所以可以很方便的适应不同宽度高度的设备. 9.png格式是很纯正的png格式,与普通的png不同的是9.png格式的图片最外围有一圈1像素的透明区域,或者说 ...