Kill only Tomcat
There is sometimes the need to kill some JVM, I usually use “killall java” and that works fine as long as that’s in fact what I want – kill ALL. But let’s say i just want to kill Tomcat and not my IDE? The below method works quite well in such an situation:
-
tcp 0 0 :::8080 :::* LISTEN 18525/java
-
[ktoso@homunculus ~]$ kill 18525 # you might need to add -9 here (SIGKILL)
A quickly hacked up version of an simple shell script to kill this tomcat could look like (I still suck at awk…):
-
kill -9 `netstat -lpn | grep 8080 | awk '{print $7}' | awk -F/ '{print $1}'`
The above obviously sux, as we’re using two awk commands after another… Ans also in the above examples, I’ve assumed that tomcat is listening on 8080, this may not always be the case, since with mod_proxy_ajp, there is no need fot it to listen on it’s default port and just the one to communicate by AJP. Let’s use it’s name to find it’s PID, we’ll use ps and grep and awk – life is simple with them. :-)
Here’s the final version of this command:
-
kill -9 `ps aux | grep catalina | awk '{print $2}'`


Post a reply