Trouble getting consistent PID of tomcat server from ps

Hello all,

I am working on a script to automate the process of restarting some tomcat servers. The versions of tomcat are pretty old and it often happens that they don't shut down gracefully and the PID needs to be manually killed. I am having a bear of a time getting a consistent PID from ps though, since sometimes other java processes show up and I get more than one PID from

`ps -ef | grep [X]ms | cut -c10-14`

(Xms is one of the values from the PID that I thought was unique to the server process, but apparently not since it double matches periodically.)

I have tried all kinds of way to trick it out, but when I run a test like

while [ `ps -ef | grep [X]ms | cut -c10-14` -eq $TOMCAT_PID ]; do
    echo IT IS ALIVE!
    sleep 1
done
echo -ne "PID results changed, dude!\n"

I always wind up getting kicked out of the loop b/c ps returned more than one value.

Any suggestions of things I can try to get the right value 100% of the time?

Thanks,

Dave

Try the "jps" utility that is shipped with JDK (JRE too?) and see if it gives you a different view.

jps - Java Virtual Machine Process Status Tool