Problem on looking for running tomcat process id

被刻印的时光 ゝ 提交于 2021-02-11 13:10:27

问题


Sometimes my tomcat server auto shutdown due to some memory issue, so I want to use the below script to check whether tomcat is running:

checkTomcatRunning.sh

TOMCAT_PID=$(ps -ef | awk '/[t]omcat/{print $2}')
echo TOMCAT PROCESSID $TOMCAT_PID

if [ -z "$TOMCAT_PID" ]
then
    echo "TOMCAT NOT RUNNING"
    sudo /opt/tomcat/bin/startup.sh
else
   echo "TOMCAT RUNNING"
fi

Below is the crontab which output log to /opt/tomcat/logs/checkTomcatRunning.log

crontab -l

*/1 * * * * /opt/tomcat/webapps/checkTomcatRunning.sh >>/opt/tomcat/logs/checkTomcatRunning.log 2>&1

in /opt/tomcat/logs/checkTomcatRunning.log, I can see 4 PID printed

cat /opt/tomcat/logs/checkTomcatRunning.log

TOMCAT PROCESSID 53585 53916 53917 53918
TOMCAT RUNNING

If run ps -ef | awk '/[t]omcat/{print $2}' from linux command line, there is only 1 PID 53585

ps -ef | awk '/[t]omcat/{print $2}'

53585

And I can only find 53585 in the running process, but not 53916 53917 53918.

ps -p 53585 53916 53917 53918

    PID TTY      STAT   TIME COMMAND
  53585 pts/0    Sl     0:50 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pk

Can anyone help to advise why there are 4 (but not 1) PIDs printed in checkTomcatRunning.log?


回答1:


Resolved by changing the path and name of the script and log file so that they don't contain "[t]omcat" keyword.



来源:https://stackoverflow.com/questions/64904316/problem-on-looking-for-running-tomcat-process-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!