1、方式一
#!/bin/sh NAME=$1 echo $NAME ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'` echo $ID echo "---------------" for id in $ID do kill -9 $id echo "killed $id" done echo "---------------"1) 将之保存为killprocess.sh
2) 调用./killprocess.sh programmename。其中programme可以为程序名字,也可以是启动程序时的命令行,只要能在ps -ef | grep programmename 之后出现所有的该程序对应的进程即可.
2、方式二
#!/bin/sh #根据进程名杀死进程 if [ $# -lt 1 ] then echo "缺少参数:procedure_name" exit 1 fi PROCESS=`ps -ef|grep $1|grep -v grep|grep -v PPID|awk '{ print $2}'` for i in $PROCESS do echo "Kill the $1 process [ $i ]" kill -9 $i done
3、方式三
ps -ef | grep procedure_name | grep -v grep | awk '{print $2}' | xargs kill -9转载: http://www.jb51.cc/article/p-whvmknvv-bee.html