Linux command get tomcat process id by name

Just add following line at the start of catalina.sh file

CATALINA_PID="$CATALINA_BASE"/logs/tomcat.pid

OR

CATALINA_PID=/tmp/tomcat.pid

And bounce tomcat. This will create a tomcat.pid file in the given path and put the Tomcat process pid in it.


This worked for me:

This will give the process id of current running tomcat

echo ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'


pgrep only search for the process name without the full path (in your case only java) and without arguments.

Since tomcat-5.5-26-rum is part of the latter, i'd search the pid with

ps -ef | grep tomcat-5.5-26-rum | grep java | awk ' { print $2 } '

The double grep is useful to discard the grep pids itself