1) 检查当前僵尸进程信息
# ps -ef | grep defunct | grep -v grep | wc -l
175
# top | head -2
top - 15:05:54 up 97 days, 23:49, 4 users, load average: 0.66, 0.45, 0.39
Tasks: 829 total, 1 running, 479 sleeping, 174 stopped, 175 zombie
# ps -ef | grep defunct | grep -v grep
2) 获得杀僵尸进程语句
# ps -ef | grep defunct | grep -v grep | awk {print "kill -9 " $2,$3}
执行上面获得的语句即可, 使用信号量9, 僵尸进程数会大大减少.
3) 过一会儿检查当前僵尸进程信息
# ps -ef | grep defunct | grep -v grep | wc -l
125
# top | head -2
top - 15:29:26 up 98 days, 12 min, 7 users, load average: 0.27, 0.54, 0.56
Tasks: 632 total, 1 running, 381 sleeping, 125 stopped, 125 zombie
发现僵尸进程数减少了一些, 但还有不少啊.
4) 再次获得杀僵尸进程语句
# ps -ef | grep defunct | grep -v grep | awk {print "kill -18 " $3}
执行上面获得的语句即可, 这次使用信号量18杀其父进程, 僵尸进程应该会全部消失.
5) 过一会儿再检查当前僵尸进程信息
# ps -ef | grep defunct | grep -v grep | wc -l
0
# top | head -2
top - 15:39:46 up 98 days, 23 min, 7 users, load average: 5.46, 2.20, 1.12
Tasks: 134 total, 1 running, 133 sleeping, 0 stopped, 0 zombie
6) 清除ZOMBIE(僵尸)进程原理
# kill -18 PPID
PPID是其父进程, 这个信号是告诉父进程, 该子进程已经死亡了, 请收回分配给他的资源.
如果还不行则看先看其父进程又无其他子进程, 如果有, 可能需要先kill其他子进程, 也就是兄弟进程.
方法是:
# kill -15 PID1 PID2
PID1,PID2是僵尸进程的父进程的其它子进程.
然后再kill父进程:
# kill -15 PPID