Reputation: 58063
Linux command line:
When i execute the following command ps -ef |grep tomcat
it shows me the following process
abcapp 28119 1 0 12:53 ? 00:00:19 /usr/java/jdk1.6.0_10//bin/java -Xmx256m -Dabc.log.file=/home/app/apps/rum/logs/dev.log -Dabc.config=dev -Dlog4j.configuration=file:///home/abcapp/env/abc_env/abc_env-1.2/config/log4j-webapp.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/home/abcapp/env/tomcat/tomcat-5.5-26-rum/conf/logging.properties -Djava.endorsed.dirs=/home/abcapp/env/tomcat/tomcat-5.5-26-rum/common/endorsed -classpath :/home/abcapp/env/tomcat/tomcat-5.5-26-rum/bin/bootstrap.jar:/home/abcapp/env/tomcat/tomcat-5.5-26-rum/bin/commons-logging-api.jar -Dcatalina.base=/home/abcapp/env/tomcat/tomcat-5.5-26-rum -Dcatalina.home=/home/abcapp/env/tomcat/tomcat-5.5-26-rum -Djava.io.tmpdir=/home/abcapp/env/tomcat/tomcat-5.5-26-rum/temp org.apache.catalina.startup.Bootstrap start
but when i issue following command it shows nothing
pgrep tomcat-5.5-26-rum OR pgrep "*-rum"
can some body help me how can i get tomcat process id by its name regex for "*-rum"
Thanks in advance.
Upvotes: 15
Views: 79056
Reputation: 487
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 }'
Upvotes: 8
Reputation: 71
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.
Upvotes: 7
Reputation: 6568
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
Upvotes: 25