aspose file tools*
The moose likes Linux / UNIX and the fly likes Can't see the tomcat server process with ps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Can Watch "Can New topic
Author

Can't see the tomcat server process with ps

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Hello
when I do ps �ef | grep $USER
im of course getting all the process names that is running, but why I see only this when it is coming to tomcat ( or any java application that is running
10262 23077 0 11:00:37 pts/17 0:13 �/jdk/jdk1.4.1/bin/java -Djava.endorsed.di
can't I give the java process some unique name ? so that I can distinct them between all other java process's?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

In Tomcat 5 there's an option to define CATALINA_PID, which indicates a file where the server's process ID gets written. You can use this to reference Tomcat by its PID. For example:

ps aex | grep `echo $TOMCAT_PID` || echo "Tomcat process has stopped running"

Probably not the best example (even if it actually works), but that's about as good as it gets.

The main problem is that Unix processes don't have abstract names, so you've got the PID or you locate it by scanning the process tree for its command line.


Customer surveys are for companies who didn't pay proper attention to begin with.
Brian Wright
Greenhorn

Joined: Dec 12, 2005
Posts: 11
Be careful with the following type of command:

ps aex | grep `echo $TOMCAT_PID` || echo "Tomcat process has stopped running"

Depending on the timing, you could well get a successful result even if the Tomcat process isn't running, as the grep command may well pick up itself in the ps listing! <command> | grep -v grep is often a lifesaver...
Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
It is old thread but info might help since I face the same problem i.e. ./shutdown.sh and ./startup.sh will not start tomcat and following command shows more than one process running.

Using this command you will kill all the process..

ps xu | grep tomcat | grep -v grep | awk '{ print $2 }' | xargs kill -9

ps xu | grep <process name> | grep -v grep | awk '{ print $2 }' | xargs kill -9


Hope this help.


SCJP, SCWCD, SCBCD, SCJD, BB Java2 and JSP1.1
vipin jos
Greenhorn

Joined: Nov 18, 2008
Posts: 24
HI Mier,

I dont know if this is a good practice...

But we usually give a java option like -DTomcat1 as the first java option.

For example in tomcat we add this in the catalina.sh

JAVA_OPTS="-DTomcat1 -server ................"

So when you do a ps -ef | grep java , we get to see the -D option and can identify the same.

Thanks,
Vipin
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11431
    
  85

Ken Boyd wrote:It is old thread

Yep

Ken Boyd wrote:Using this command you will kill all the process..

ps xu | grep tomcat | grep -v grep | awk '{ print $2 }' | xargs kill -9


Since you are using awk, you really do not need all the grep statements. The following should do exactly the same task:

Basically, the text between the forward slashes must be matched for the code inside the braces to be executed, and awk automatically uses regular expressions if they are listed. So [t]omcat will only match the text "tomcat" in the ps output. Since the awk statement itself does not have the word tomcat (it has the square brackets around the t) it will not match.

Of course you may prefer to look at the killall command for a simpler approach (assuming you have it on your operating system).


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Balaji Soundarajan
Ranch Hand

Joined: Jan 23, 2009
Posts: 59
How to check The Tomcat process is running or not on UNIX using command?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11431
    
  85

What did you try from the suggestions above?

What parts did you understand / don't understand?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

If the process name is tomcat, you don't need grep, but may use:


Ubuntu comes with pidof:

Isn't tomcat started by the sysvinit-system? Maybe
or something else, similar can be used too.

Of course, if the java program is started without script, it's harder to find the right java program, and the solutions above are the only working ones.


http://home.arcor.de/hirnstrom/bewerbung
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

Try this:

ps -ef | grep catalina

The startup.sh script runs catalina.sh which in turn runs java passing in org.apache.catalina.startup.Bootstrap as the main class. The -e option to ps gets all processes, the -f option gets full info which includes the command line used to start the process, and the grep searches the results for 'catalina', which should point out the java process running Tomcat.


JBoss In Action
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
Many unix (therfore java) processes automatically go in the background, and therefore cannot be seen with a normal 'ps' command.

You need to use something to see background processes, for eg: use: 'listps'

#listps

OR

#listps | grep java

If you do not have 'listps' by default on your linux OS, you may have to install that 'module'.

Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't see the tomcat server process with ps