自動清理殭屍程序及STOP程序指令碼
阿新 • • 發佈:2020-09-17
#!/bin/bash echo "##############殭屍程序##############" check=`ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]'` if [ -n "$check" ];then echo "發現殭屍程序!" for pid in `ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' |awk '{print $3}'` do `kill -9 $pid` done check1=`ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]'` if [ -n "$check1" ];then echo "未能殺掉殭屍程序,請選擇是否殺死父程序!" read -p "請輸入y/n: " x fi if [ $x==y ]; then echo "正在執行殺死父程序!" for ppid in `ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' |awk '{print $2}'` do `kill -9 $ppid` done elif [ $x==n ]; then break fi else echo "未發現殭屍程序!" fi echo "##############STOP程序##############" check_t=`ps -A -o stat,ppid,pid,cmd | grep -e '^[T]'` if [ -n "$check_t" ];then echo "發現STOP程序!" for pidone in `ps aux |grep -w T |grep -v grep |awk '{print $2}'` do `ps -ef |grep $pidone |grep defunct |awk '{print "kill -9 " $2 " "$3}'` done else echo "未發現STOP程序!" fi