Linux 如何杀死僵尸进程

时间:2022-02-04 08:07:04

问题描述:

shell > top
top - :: up days, :, user, load average: 0.23, 0.81, 1.07
Tasks: total, running, sleeping, stopped, zombie
Cpu(s): 3.6%us, 0.8%sy, 0.0%ni, 95.3%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 24596748k total, 3346824k used, 21249924k free, 50344k buffers
Swap: 8388600k total, 9704k used, 8378896k free, 1649016k cached

# 发现有三个僵尸进程 3 zombie ,这是因为先杀死了父进程导致

shell > ps aux | grep Z
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 0.0 0.0 ? Zs : : [yiic_elastic_kt] <defunct>
root 0.0 0.0 pts/ R+ : : grep Z

# 不给面子,已经自动死了两个,估计是太阳出来了

shell > kill - 

# 这样是杀不死的,还顽强的存活着

解决方法:

shell > ps -ef | grep defunct
root : ? :: [yiic_elastic_kt] <defunct>
root : ? :: [yiic_elastic_kt] <defunct>
root : ? :: [yiic_elastic_kt] <defunct>
root : ? :: [yiic_elastic_kt] <defunct>
root : pts/ :: grep defunct

# 我去,又跑出来三个...

shell > ps -ef | grep defunct | awk '{print $3}' | xargs -i kill {}

# $3 是这些僵尸进程的父进程 PID ( PPID ),杀之!

shell > ps -ef | grep defunct
root : pts/ :: grep defunct

# 已经灰飞烟灭!