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?
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
posted
0
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
posted
0
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..
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).
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.
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.