PID of a script file
Hi all,
I have a script (A.sh) to start tomcat server (catalina.sh) After executing A.sh i need to get the PID of the A.sh file. if i do a ps -ef | grep A.sh doesn't return anything , could anybody please help me to get this done Thanks a lot sajith |
What is in the script A.sh that keeps it running?
Remember you will only get a PID in that fashion if the script is still running or in a wait state |
Post the contents of A.sh here - grail is 100% - if your script merely invokes one of the Tomcat startup scripts; your script will terminate and thus you may not see it in the ps -ef
|
Thanks for the quick responses alli_yas and grail
the content in my A.sh script is as follows #!/bin/sh if [ "$1" = "run" ]; then exec sh $CATALINA_HOME/bin/catalina.sh run elif [ "$1" = "stop" ]; then exec -a pse sh $CATALINA_HOME/bin/catalina.sh stop fi the content in catalina.sh script is the standard catalina.sh which comes with Apache Tomcat Thanks in advance sk |
If you did not use the exec command ( which quits the script after the command is run ) you could then add a wait $(pidof catalina) at the end of the script to tell it to wait until catalina exits ( when you issue a STOP ) or until it dies for any reason ( if you issue a START ).
|
Thanks William,
that worked, when i remove the exec command Now I'm having some other question, that is, when i do a ps - ef | grep A.sh , it outputs the PID, then i need to execute "cat /proc/<PID>/status" and the name of the process appear as "sh" Is there any way that i can customise the name of the process that im getting? Thanks in advance sa |
I'm assuming you are executing the shell script with sh, but then it will also have the process name sh.
Instead of running the script with Code:
$ sh A.sh Code:
$ chmod u+x A.sh # You only need to do this once Code:
$ exec A.sh |
Cool
Thanks wiliaam and all the others. i got my prob solved Thanks |
Quote:
Remember you can replace the grep and kill with this Code:
killall A.sh |
All times are GMT -5. The time now is 10:45 PM. |