定时清理僵尸进程.md 928 B


title: 定时清理僵尸进程 tags: [] id: '2448' categories:

  • - 运维 date: 2022-10-27 22:22:35 ---

之前Docker搭建ServerStatus给树莓派装了个监控,发现CPU使用率偏高,一看,发现逗逼宝塔面板产生了几万个僵尸进程,只好临时用北洋的青春的脚本来定时清理一下。

#!/bin/bash
zombie_check=`ps -A -o stat,ppid,pid,cmd  grep -e '^[Zz]'`
 
if [ -n "$zombie_check" ];
 then
 echo "Start to handle the zombie!!!!!"
 for i in `ps aux grep -w Z grep -v grep awk '{print $2}'`
 do
 `ps -ef grep $i grep defunctawk '{print "kill -9 " $2 " "$3}'`
 done
else
 echo "There is no zombie !!!!!"
fi
  • nano kill_zombie.sh
  • chmod +x kill_zombie.sh
  • sudo ./kill_zombie.sh
  • crontab -e
  • 30 * * * * /usr/bin/sudo /home/pi/kill_zombie.sh