Thread: process info from PID

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    process info from PID

    Hi, I'm kind of new in c programming.
    I'm trying to make a simple program, that displays all of current running processes on my computer and their names.
    My idea is that i would store all the directories beginning with a number from /proc/ in a list, and then get name for each PID and print it out.
    Am i going into the right direction here?
    I know how to get all PIDs, but i can't figure out how to get process name of specific PID.

    BTW: i don't want to use functions system(..) and popen(...)

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can always find the executable of a process by following the symbolic link at /proc/<pid>/exe. In addition, you can find the command line in /proc/<pid>/cmdline. There's a lot more stuff in that directory.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Why you need to write this program ? What's wrong with ps ?

    Valery

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2
    CornedBee thanks! That actually worked quite fine.

    Valery: I was asking myself the same question when i got that assignment.

    Regards, Miha.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. process id
    By bradleyd in forum C Programming
    Replies: 6
    Last Post: 06-30-2007, 05:21 PM
  4. Info on specific process
    By NoFearXD in forum Windows Programming
    Replies: 3
    Last Post: 05-20-2007, 07:42 PM
  5. Problems with child process creation
    By Niloc1 in forum C Programming
    Replies: 0
    Last Post: 02-09-2003, 02:52 PM