The stop script shutdown.sh for Tomcat under Linux often fails, causing the Tomcat process not to shut down. Therefore, you can only manually find the process ID and then use the KILL command to force the stop. Check it every time, and then kill the process. I feel a bit of trouble, so I write this action in the script. First, the ideaThis script is actually 2 steps, get the process ID first, then kill the process.
(1) method to get the process IDThis can be obtained with the awk command.
ps -ef | grep 你的进程 | grep -v grep | awk ‘{print $2}‘
This grep is filtered out with-V, and the 2nd parameter is the process ID, using the awk command.
(2) method of killing processThis will kill you directly-it's OK.
kill -9 你的进程id
Second, the script codeThe code is as follows (/root/tomcat-instance/shutdown_sp.sh):
sp_pid=`ps -ef | grep sp-tomcat | grep -v grep | awk ‘{print $2}‘`
if [ -z "$sp_pid" ];
then
echo "[ not find sp-tomcat pid ]"
else
echo "find result: $sp_pid "
kill -9 $sp_pid
fi
Note: when using, you need to replace the first line of Sp-tomcat with the one you wish to kill.
Description: It may be said that the script will error when there are multiple process IDs for the lookup process. In fact, there is a space between them when there are multiple process IDs. When the kill command kills more than one process at a time, the process ID needs a space. So you don't need a For loop to kill the process.
Script to find the process ID and force stop process under Linux