Shell 根据名称杀掉进程

 

代码如下:

#!/bin/sh  

# 从命令行读取进程名称
NAME=$1  

echo "---------------"

echo 'killing ->' $NAME  

# 过滤进程列表,不显示grep对应的进程,awk从第二列获取进程ID
ID=`ps -ef | grep "$NAME" | grep -v "grep" | awk '{print $2}'`
# ps -ef | grep "template.py" | grep -v "grep" | awk '{print $2}'
echo 'found ID list:' $ID
for id in $ID
    do
    # 杀掉进程
    kill -9 $id
    echo "killed $id"
    done

echo "---------------"

 

posted @ 2018-03-20 11:02  Ficow  阅读(2910)  评论(0编辑  收藏  举报