views:

171

answers:

2

I need to retrieve process information in a C/C++ program. I need at least basic things like CPU% and memory usage, but additional details would be useful as well.

The problem is that I need to use this information in a portable program, that will run on multiple platforms: windows, linux, MAC and possibly Solaris too.

Is there a library that I can use or do I need to write my own HAL for the different platforms? I tried to look on google, but I couldn't see anything obvious.

A: 

This information must be retrieved from the OS.
By definition this is non portable, but there are a couple of OS abstraction layers out there. The one that springs to mind is ACE.

Martin York
ACE doesn't seem to contain what OP asked for. Qt, btw, doesn't, either. Seems to be non-trivial...
The problem is trivial. It is just that each system is different.
Martin York
+1  A: 

I can't help you with a complete solution, but here's a link to my CPULoadMeter class, which you can use to poll CPU usage information over time. It works under MacOS/X, Windows, and Linux (and possibly other Unixy-OS's that have /proc/stat also, I don't know). Perhaps you can use it as a starting point.

https://public.msli.com/lcs/muscle/muscle/util/CPULoadMeter.h https://public.msli.com/lcs/muscle/muscle/util/CPULoadMeter.cpp

Jeremy Friesner