Get number of running processes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chris.tice@gmail.com

    Get number of running processes

    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_cou nt()) rather than perform this hackish
    workaround.

    Thanks for any help!
    - Chris

  • Vladimir Oka

    #2
    Re: Get number of running processes

    chris.tice@gmai l.com opined:
    [color=blue]
    > 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_cou nt()) rather than perform this hackish
    > workaround.[/color]

    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.progr ammer 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>

    Comment

    • Chris

      #3
      Re: Get number of running processes

      Thanks for the redirection.

      Comment

      Working...