Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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.

  2. #2
    Just 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...

  3. #3
    Just 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?

  4. $spacer_open
    $spacer_close
  5. #4
    Just 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....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •