• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't see the tomcat server process with ps

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Wright
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vipin jos
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Balaji Soundarajan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to check The Tomcat process is running or not on UNIX using command?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you try from the suggestions above?

What parts did you understand / don't understand?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic