Get number of running processes

C

chris.tice

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
 
V

Vladimir Oka

(e-mail address removed) 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top