Use a shell script to find the process ID corresponding to the program and kill the process

original:

https://blog.csdn.net/boshuzhang/article/details/50696612

 

 

 

#!/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), save it as killprocess.sh
2), call ./killprocess.sh programmename. Where programme can be the program name or the command line when starting the program, as long as all the processes corresponding to the program can appear after ps -ef | grep programmename

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324746958&siteId=291194637