I want my (C/C++ based) program to display a numeric indicator of how many processes are currently present on the local system. The number-of-running-processes value would be queried often (e.g. once per second) to update my display.
Is there a lightweight way to get that number? Obviously I could call "ps ax | wc -l", but I'd prefer not to force the computer to spawn a process and parse several hundred lines of text just to come up with a single integer.
This program will be running primarily under Linux, but it might also run under MacOS/X or Windows also, so techniques relevant to those OS's would be helpful also.
Ideally I'm looking for something like this, except available under Linux (getsysinfo() appears to be more of a Minix thing).