Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-16-2006, 06:37 AM   #1
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 ""

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

If these scripts are running parallely , I would like to the get the pid into a "shell script variable" of 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 running from "folder1"

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

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

Rep: Reputation: 66
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:
echo $$ > /var/run/
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
Senior Member
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
also do that :
trap "rm -f /var/run/; exit" INT TERM EXIT


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:29 AM.

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