按进程名终止进程

按进程名终止进程

#!/bin/bash

echo "Terminate process(es) has " $1 " in name."
echo "Self pid " $$
echo "Self name " $0

pids=$(ps -ef | grep $1 | grep -v grep | grep -v $0 | awk '{print $2}')
pid_array=($pids)

for x in ${pid_array[@]}; do
    echo "pid: " $x
    kill $x
done

echo "Search for $1 again"
ps -ef | grep $1
echo "Finished."

 

posted on 2021-03-11 10:23  liujx2019  阅读(85)  评论(0编辑  收藏  举报

导航