Thread: Active process list

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732

    Active process list

    Is there any function or system routine which provided me with all the active process running on the machine. I have tried with the piping the ps command and parsing through the output. Is there any functions at all which does that. I am pretty sure there should be some system function which does that.

    I am on Linux, GCC.

    Thanks a lot

    ssharish

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm pretty sure there is a /proc file [1] under Linux. If you "strace ps", you can probably find the file that is being opened as part of that.

    [1] It is of course not a "real file", but a pseudo-file that is just showing the current processes.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Hi map, thanks for your reply. I tried your suggestion, you where true that it should getting it from file and of course it is. The problem is, there are all not in just one single file. And perhaps all the process list is getting it from a dozens of folder under /proc. And may be i would me having issues with permission and all is guess.

    I think, i need to go with the ps command. What i am trying to do is look for a process and see if its running or not. If running kill that process. I think we could do that through grep command

    Code:
    ps | grep <process name>
    This is what i am doing. Is there any better way of doing this. Any comments

    Thank you

    ssharish

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, the common way to do that is to create a file "myproc.pid" in some known place (e.g. /temp) that contains the process id (the process itself can write that process).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    pkill <processname> should work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pleas take a look & give a critique
    By sh3rpa in forum C++ Programming
    Replies: 14
    Last Post: 10-19-2007, 10:01 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 09:27 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM