Results 1 to 5 of 5
Hi, is that possible to get the process id, using a process name in c program.
In shell it is possible using pgrep, but in c program ??
Does any ...
- 12-03-2009 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 30
Getting process ID using process name in C ??
Hi, is that possible to get the process id, using a process name in c program.
In shell it is possible using pgrep, but in c program ??
Does any one has the answer ??
- 12-03-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
I'm not aware of a standard function to get this information, but you can look at the source for the pidof system command to see how it does that.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 12-03-2009 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
FWIW, most functions that do this sort of thing access the /proc file system where process ids of all running processes exist as directories and they have entries for such things as the command line it was started with, a link to the executable that is running the process, etc.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 12-04-2009 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 30
you can refer this link:
linuxforums.org/forum/linux-programming-scripting/40078-c-printing-linux-process-table.htm
few question arises with this link
if you want to create a single instance application in linux using daemon process, then problem arises.
1. when you run the daemon say XX 1st time, it checks for the process XX. the process exist since we are running the same, so it will say that the program is running and it will come out. how to solve this problem.
- 12-04-2009 #5Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
