Get number of running processes

Discussion in 'C Programming' started by chris.tice@gmail.com, Apr 29, 2006.

  1. Guest

    Hi,

    I am looking for an easy way to find the total number of running
    processes on a given machine in a C program. Currently I am doing
    this:

    system("ps -e | wc -l > count.txt");

    then reading the number back into the program from the text file. I
    was wondering if there was a function call that would do this (ie. int
    count = get_process_count()) rather than perform this hackish
    workaround.

    Thanks for any help!
    - Chris
     
    , Apr 29, 2006
    #1
    1. Advertising

  2. Vladimir Oka Guest

    opined:

    > Hi,
    >
    > I am looking for an easy way to find the total number of running
    > processes on a given machine in a C program. Currently I am doing
    > this:
    >
    > system("ps -e | wc -l > count.txt");
    >
    > then reading the number back into the program from the text file. I
    > was wondering if there was a function call that would do this (ie.
    > int count = get_process_count()) rather than perform this hackish
    > workaround.


    In standard C no, there isn't. Your implementation, or some system
    specific library may well provide one. You seem to be running a *nixy
    system, so comp.unix.programmer or similar may be the place to ask.

    --
    One does not thank logic.
    -- Sarek, "Journey to Babel", stardate 3842.4

    <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
     
    Vladimir Oka, Apr 29, 2006
    #2
    1. Advertising

  3. Chris Guest

    Thanks for the redirection.
     
    Chris, Apr 29, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Divyang M
    Replies:
    4
    Views:
    1,054
    Divyang M
    Feb 17, 2005
  2. Rusty Shackleford

    Worker Processes Running counter?

    Rusty Shackleford, Oct 5, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    422
    Rusty Shackleford
    Oct 5, 2005
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,203
    David Schwartz
    Dec 9, 2003
  4. Jason
    Replies:
    5
    Views:
    1,341
    Jason
    Nov 20, 2006
  5. Marc Heiler
    Replies:
    1
    Views:
    191
    Robert Klemme
    May 24, 2009
Loading...

Share This Page