Linux命令按名称获取tomcat进程ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14146536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux command get tomcat process id by name
提问by d-man
Linux command line:
Linux命令行:
When i execute the following command ps -ef |grep tomcat
it shows me the following process
当我执行以下命令时,ps -ef |grep tomcat
它会显示以下过程
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"
有人可以帮助我如何通过“*-rum”的名称正则表达式获取 tomcat 进程 ID
Thanks in advance.
提前致谢。
采纳答案by Davide Berra
pgrep only search for the process name without the full path (in your case only java) and without arguments.
pgrep 只搜索没有完整路径的进程名称(在你的情况下只有java)并且没有参数。
Since tomcat-5.5-26-rumis part of the latter, i'd search the pid with
由于tomcat-5.5-26-rum是后者的一部分,我会用
ps -ef | grep tomcat-5.5-26-rum | grep java | awk ' { print } '
The double grep is useful to discard the grep pids itself
双 grep 可用于丢弃 grep pid 本身
回答by Vikrant Telkar
Just add following line at the start of catalina.sh
file
只需在catalina.sh
文件开头添加以下行
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.
和反弹tomcat。这将tomcat.pid
在给定路径中创建一个文件,并将 Tomcat 进程 pid 放入其中。
回答by jaydip jadhav
This worked for me:
这对我有用:
This will give the process id of current running tomcat
这将给出当前正在运行的 tomcat 的进程 ID
echo ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'
回声 ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'