vim kill_process.sh
if [ "$1" = "" ]; then echo "Usage: sh $0 <processname>" exit 0 fi for i in {1..100} do s1=`ps -ef|grep $1|grep -v "sh $1"|grep -v "grep"|awk '{print $2}'` count=0 echo "$s1"|while read line do if [ "$line" != "" ]; then echo "kill pid $line" kill $line count=count+1 else echo "the pid is NULL" fi done if [ "$count" -eq "0" ]; then break fi sleep 2 done
使用范例:
sh kill_process.sh tomcat