Kill all processes tomcat

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/GoSaint/article/details/90139332

Kill all processes tomcat

Buddha Nianhua  Buddha Nianhua  today

 


We usually use the tomcat process need to kill one or a few tomcat process, generally using a command ps -ef | grep tomcat to get the corresponding process number, then use the kill -9 pid to kill. I have written here is to kill all the tomcat process through a shell script.

Tomcat start a process, and then use the ps -ef | grep tomcat to see the process:

There are two processes can see the number, the second of which is a command grep tomcat process itself, so we do not need this process. So using a reverse lookup command grep -v grep. This effect grep command is not required in this process.

We use the following command to get only the tomcat process id:

        ps -ef|grep tomcat|grep -v grep

At this time, only to see the process ID of tomcat. So how do you get the process ID id = 4960 do?

Use awk command, which is output line by line, we use awk '{print $ 2}' 4960 can obtain this it! {Print $ 2} is to obtain a second variable. And separated by a space.

So the whole command is:

ps -ef | grep tomcat | grep -v 'grep' | awk '{print $ 2}'

After we get all the process ID, you can kill traversal cycle. Therefore, all of the shell script as follows:

#! /bin/bash

tomcat_pid=`ps -ef|grep tomcat|grep -v 'grep'|awk '{print $2}'`

echo ${tomcat_pid}

for id in ${tomcat_pid}

do

    kill -9 $id

    echo "killed ${id}"

done

Guess you like

Origin blog.csdn.net/GoSaint/article/details/90139332