天天看點

Linux Shell根據程序名殺死程序!/bin/sh

功能是給出一個程序名,就會把關聯程序id全部kill掉。

shell腳本源碼如下:

if [ $# -lt 1 ]

then

echo "缺少參數:procedure_name"

exit 1

fi

process=<code>ps -ef|grep $1|grep -v grep|grep -v ppid|awk '{ print $2}'</code>

for i in $process

do

echo "kill the $1 process [ $i ]"

kill -9 $i

done

如果覺得上邊的代碼忒複雜,可以直接使用下面的一句來實作。

ps -ef | grep procedure_name | grep -v grep | awk '{print $2}' | xargs kill -9

繼續閱讀