#include <statgrab.h>
sg_cpu_percents *sg_get_cpu_percents(void);
sg_cpu_stats *sg_get_cpu_stats(void);
sg_cpu_stats *sg_get_cpu_stats_diff(void);
The value stored (the "ticks") will vary between operating systems. For example Solaris has a total of 100 per second, while Linux has substantially more. Also, different operating systems store different information - you won't find nice cpu on Solaris for example.
Because of this, you will ideally always want to work on a scale against the total, or in percentages.
sg_get_cpu_percents() returns a pointer to a static sg_cpu_percents. The function calls sg_get_cpu_stats_diff() and changes the values into percentages. If it has never been called before (and nor has sg_get_cpu_stats() or sg_get_cpu_stats_diff()), the returned percentages will be the systems total ever since its uptime. (Unless the counters have cycled)
typedef struct{ long long user; long long kernel; long long idle; long long iowait; long long swap; long long nice; long long total; time_t systime; }sg_cpu_stats;
typedef struct{ float user; float kernel; float idle; float iowait; float swap; float nice; time_t time_taken; }sg_cpu_percents;