LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-16-2006, 06:37 AM   #1
ravi2082
LQ Newbie
 
Registered: Aug 2006
Posts: 5

Rep: Reputation: 0
getting pid using PS command by inputting full comand name


Hi Guys

Using ps command we can get the details of a process by giving a command -C option.
ps -C "Script.sh"

I have a Script.sh in many folders which running
like /home/folder1/Script.sh /home/ravi/Script.sh.

If these scripts are running parallely , I would like to the get the pid into a "shell script variable" of Script.sh running from "folder1". I have tried using
ps -aux|grep /home/folder1
But in the above case I get even the "grep" ps details.

Please give me ps format command which can take full command name and give the pid of the Script.sh running from "folder1"

Thanks
Ravi
 
Old 08-16-2006, 08:04 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
ps -aux | grep /home/folder1 | grep -v "grep"
 
Old 08-16-2006, 08:24 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
It is not clear, but if you want the pid of a running script, inside this very script, you already have it: It is in $$ variable.

Several daemons and scripts running at linux, wrote its pid to a external file, in a standard location: /var/run. Take a look, there is several .pid files there. You can use something like that to make public the pid of your script. Just do in your script:
Code:
echo $$ > /var/run/myscript1.pid
Other process had just to read that file. Very simple.

PS: Just remember to remove the pid file at exit of your script.

Last edited by marozsas; 08-16-2006 at 08:25 AM.
 
Old 08-16-2006, 08:34 AM   #4
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
also do that :
trap "rm -f /var/run/myscript1.pid; exit" INT TERM EXIT
 
  


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
how do I extract the pid field from ps aux command RajRed Linux - Newbie 7 12-09-2013 01:43 PM
PID Kill Script or command ? Webmin rapture_1 Linux - General 1 11-02-2005 12:11 PM
Inputting a text file in to the "rm" command R4z0r Linux - General 5 12-28-2003 06:44 PM
PID display command for kernel modules jedblack Linux - Software 1 11-28-2003 07:01 PM
how to get PID without using pidof command? ruchika Programming 2 09-22-2003 04:12 PM


All times are GMT -5. The time now is 04:32 AM.

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