Linux uses shell script to close the specified application

Under Linux, we often use the following methods to kill applications, that is, first find out the pid of xxx, and then kill -9 pid to kill the process.

ps -ef | grep xxx
kill -9 xxid

We can be more automated, create a new shut.sh script, write the following content.

#!/bin/bash
tmp=`ps -ef | grep YOUR_NAME | grep -v grep | awk '{print $2}'`
echo ${tmp}
for id in $tmp
do
kill -9 $id
echo "killed $id"
done

Where YOUR_NAME is replaced with the name of the process you want to kill, grep -v excludes grep itself, awk can get the pid according to the space interval, and then loop kill.

Conclusion As long as ps -ef | grep YOUR_NAME can find out, this program can terminate them normally.

Guess you like

Origin blog.csdn.net/u014126257/article/details/108693322