Faisal khan Faisal khan - 7 days ago 4x
Linux Question

Linux command get tomcat process id by name

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.


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