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?
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...
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 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.