Results 1 to 10 of 11
Hi friends,
can anyone tell me how do i get(using coding) a pid of the process that is running when i know only the name of the process.... please gimme ...
- 04-17-2007 #1Just Joined!
- Join Date
- Aug 2006
- Posts
- 76
get the PID
Hi friends,
can anyone tell me how do i get(using coding) a pid of the process that is running when i know only the name of the process.... please gimme a ready code to find the pid of the process when i know only the process name.. ?
thanks..
- 04-17-2007 #2Just Joined!
- Join Date
- Apr 2007
- Posts
- 11
pid
Run "ps -ef | grep process name".
Originally Posted by lovlin
- 04-17-2007 #3Just Joined!
- Join Date
- Aug 2006
- Posts
- 76
thanks for reply Faizsir

will this give the process ID when is give like..."ps -ef | grep pppd" ????...can i get some sort of C code for this ???
- 04-18-2007 #4
Lovlin... you have the answer in the title of this thread itself
Use getpid() system call.
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 04-18-2007 #5Just Joined!
- Join Date
- Aug 2006
- Posts
- 76
thanks for reply Lakshmipathi,
but when i am writing a C code....it gives the pid of the process that contains main right ??? so inside the main say if i am spawning sshd then how do i get the sshd's pid knowing that the name of the process is "sshd"
- 04-19-2007 #6
are using fork() to create a new process sshd...
if so check man fork().
please cut n paste some codes...- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 04-19-2007 #7Just Joined!
- Join Date
- Sep 2006
- Posts
- 22
Hi lovlin,
I got your issue. There is a shell command called "pgrep". To get the pid of process for which you know its name, tune it like below.
Code:pgrep -x <process name>
- 04-19-2007 #8Just Joined!
- Join Date
- Sep 2006
- Posts
- 22
Hi lovlin,
I got your issue. There is a shell command called "pgrep", which will throw the PID into STDOUT. To get the pid of process for which you know its name, tune it like below.
But as this is shell command, it can be used only with system() or with exec(). If someone else comes up with system call equivalent of pgrep, it would be great.Code:pgrep -x <process name>
- 04-19-2007 #9Just Joined!
- Join Date
- Jan 2006
- Location
- India
- Posts
- 52
Hi,
when you are looking for PID with in a process which is spawning then you can alway use the getpid() call. because the fork() will return the pid of the child to the parent and 0 to the child.
Let me know your requirements.
--REgards
rajesh
- 04-19-2007 #10
an even simpler way would be to use the "pidof" command.
will return imaginitively enough the process id of the command "firefox-bin"Code:pidof firefox-bin
"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327


