Results 1 to 4 of 4
Hi, im trying to write some code that will operate somewhat like ps but much simpler.
I need it so that The program will output all PID's and CMD names ...
- 11-23-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
How to get list of PID's (like ps)
Hi, im trying to write some code that will operate somewhat like ps but much simpler.
I need it so that The program will output all PID's and CMD names in the /proc filesystem (like ps -e).
I think i know how to get the CMD name once i actually have the PID, but my problem is I dont know how to get the PID's in /proc.
Is there some way of looping through all PID's? Even if someone could just direct me to somewhere in the kernel that does this so i can look at it and use it that would be great.
Thanks.
- 11-23-2007 #2Just Joined!
- Join Date
- Nov 2007
- Location
- Camp Pendleton
- Posts
- 55
Well, the `ps' command really just reads from /proc. The information there is from the kernel...
- 11-23-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
So basically I just have to read through /proc?
So how would I do this in C and how would i get the PID from each entry in /proc?
- 11-23-2007 #4Just Joined!
- Join Date
- Nov 2007
- Location
- Camp Pendleton
- Posts
- 55
Well, I'd start with downloading a copy of procps and see how they did it. But the directories in /proc that are all numbers are your pids....


Reply With Quote
