If you want to get the process id (PID) of your tomcat you can do something like this:
ps h -C java -o "%p:%a" | grep catalina | cut -d: -f1
If you want to kill this tomcat, because it didn’t shut down properly you can use the following:
kill -9 `ps h -C java -o "%p:%a" | grep catalina | cut -d: -f1`
A better way is to set the environment variable CATALINA_PID. If this variable is set the PID is written in the specified file (here catalina.pid) on tomcat startup.
export CATALINA_PID=/opt/tomcat/catalina.pid /opt/tomcat/bin/startup.sh
Now killing the tomcat is also easier: You can can stop tomcat with -force, which will kill the tomcat process after shutdown (-force only works if CATALINA_PID is set).
export CATALINA_PID=/opt/tomcat/catalina.pid /opt/tomcat/bin/shutdown.sh -force
(If you set CATALINA_PID in your .bashrc you don’t have to set it before startup/shutdown)
Advertisement