运行维护:Centos系统批量查杀僵尸进程
运行环境 Runtime environment
背景
类似开启Win系统的任务管理器,输入top命令
top
1 2 3 4 5 6 7
| top - 16:10:53 up 25 days, 11 min, 2 users, load average: 3.00, 3.21, 2.93 Tasks: 595 total, 2 running, 593 sleeping, 0 stopped, 22 zombie %Cpu(s): 7.7 us, 1.6 sy, 0.0 ni, 90.7 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st KiB Mem : 65536176 total, 37648408 free, 22068912 used, 5818856 buff/cache KiB Swap: 52428796 total, 52428796 free, 0 used. 42291636 avail Mem
....
|
22 zombie 代表当前存在22个僵尸进程
查询僵尸进程
以防万一,还是查看一下僵尸进程都有的详细信息。
因为状态为 z或者Z 的进程为僵尸进程,所以使用grep抓取stat状态为zZ进程
ps -A -o stat,ppid,pid,cmd | grep -e ‘^[Zz]’
查询结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| jump 19108 456925 0 15:16 pts/1 00:00:00 grep --color=auto chrome jump 256360 245064 0 May12 ? 00:00:08 [chrome] <defunct> jump 256360 245064 0 May12 ? 00:00:08 [chrome] <defunct> jump 256360 245064 0 May12 ? 00:00:08 [chrome] <defunct> jump 256581 245064 0 May12 ? 00:00:00 [chrome] <defunct> jump 265115 245064 0 May12 ? 00:00:00 [chrome] <defunct> jump 276491 245064 0 May12 ? 00:00:08 [chrome] <defunct> jump 288434 245064 0 May12 ? 00:00:00 [chrome] <defunct> jump 310725 238834 0 11:06 ? 00:00:00 [chrome] <defunct> jump 311343 245064 0 May12 ? 00:00:08 [chrome] <defunct> jump 317738 238834 0 11:08 ? 00:00:01 [chrome] <defunct> jump 319714 238834 0 11:08 ? 00:00:01 [chrome] <defunct> jump 335549 238834 0 11:12 ? 00:00:00 [chrome] <defunct> jump 357632 355570 0 14:09 ? 00:00:01 [chrome] <defunct> jump 396095 355570 0 14:15 ? 00:00:01 [chrome] <defunct> jump 399044 355570 0 14:16 ? 00:00:00 [chrome] <defunct> jump 403243 355570 0 14:16 ? 00:00:00 [chrome] <defunct> jump 419426 238834 0 11:29 ? 00:00:00 [chrome] <defunct> jump 442668 238834 0 11:35 ? 00:00:00 [chrome] <defunct> jump 442746 355570 0 14:22 ? 00:00:00 [chrome] <defunct> jump 448704 238834 0 11:40 ? 00:00:00 [chrome] <defunct> jump 449129 355570 0 14:27 ? 00:00:00 [chrome] <defunct> jump 452443 355570 0 14:40 ? 00:00:00 [chrome] <defunct> jump 452476 355570 0 14:40 ? 00:00:00 [chrome] <defunct>
|
scrapty+gerapy-pyppeteer 爬虫采集导致大量的chrome浏览器残余进程。
批量杀死僵尸进程
获取所有僵尸进程的pid,然后批量处理
ps -A -o stat,ppid,pid,cmd | grep -e ‘^[Zz]’ | awk ‘{print $2}’ | xargs kill -9
总结
批量杀死进程真是好东西。