LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-22-2010, 03:18 AM   #1
sajhak
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Rep: Reputation: 0
Question 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
 
Old 07-22-2010, 03:20 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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
 
Old 07-22-2010, 03:37 AM   #3
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
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
 
Old 07-22-2010, 03:59 AM   #4
sajhak
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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

Last edited by sajhak; 07-22-2010 at 06:19 AM.
 
Old 07-22-2010, 04:27 AM   #5
William (Dthdealer)
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Debian Testing
Posts: 99
Blog Entries: 39

Rep: Reputation: 19
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 ).
 
Old 07-22-2010, 05:08 AM   #6
sajhak
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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

Last edited by sajhak; 07-22-2010 at 06:18 AM.
 
Old 07-22-2010, 06:00 AM   #7
William (Dthdealer)
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Debian Testing
Posts: 99
Blog Entries: 39

Rep: Reputation: 19
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
Make the file executable
Code:
$ chmod u+x A.sh # You only need to do this once
And then execute it with either
Code:
$ exec A.sh
 ... or ...
$ ./A.sh # Recommended, but only if you are in the right directory
 ... or ...
$ directories/where/the/script/is/located/A.sh
 
Old 07-22-2010, 06:20 AM   #8
sajhak
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Cool

Thanks wiliaam and all the others.

i got my prob solved

Thanks
 
Old 07-22-2010, 06:29 AM   #9
William (Dthdealer)
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Debian Testing
Posts: 99
Blog Entries: 39

Rep: Reputation: 19
Quote:
Originally Posted by sajhak View Post
Cool

Thanks wiliaam and all the others.

i got my prob solved

Thanks
You're welcome

Remember you can replace the grep and kill with this
Code:
killall A.sh
Killall takes the name of the process, unlike kill which requires the PID.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
(20014)Internal error: Error retrieving pid file /var/run/apache2.pid yuri16 Linux - Server 0 07-28-2009 04:11 AM
reading pid from pid file in C language shifter Programming 1 05-14-2008 11:49 AM
CentOS 4 (Fedora Core) init script - create PID file cejennings_cr Linux - Newbie 1 07-10-2006 09:22 AM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 09:05 PM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 07:25 PM


All times are GMT -5. The time now is 03:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration