Since you say no to Objective-C, we will exclude most MacOS frameworks.
You can get processor time using getrusage (), which gives the total amount of User and System CPU load times for your process. To get the percentage of CPU, you will need to instantly display getrusage values ββonce per second (or, as necessary).
#include <sys/resource.h> struct rusage r_usage; if (getrusage(RUSAGE_SELF, &r_usage)) { /* ... error handling ... */ } printf("Total User CPU = %ld.%ld\n", r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec); printf("Total System CPU = %ld.%ld\n", r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec);
There is an RSS field in the getrusage structure, but it always looks zero in MacOS X 10.5. Michael Knight wrote a blog post a few years ago on how to spot RSS.
DGentry Oct 21 '08 at 2:11 2008-10-21 02:11
source share