int strsplit (char *string, char **fields, size_t size);
int main(void) { FILE *stat; char *fields[9]; int numfields;
unsigned int ncores;
unsigned int idle; unsigned int old_idle = 0;
while (1) { /* * The cpu sum line SHOULD be the first line * on /proc/stat, or things will get wrong. */ if ((stat = fopen("/proc/stat", "r")) == NULL) { perror("fopen"); exit(EXIT_FAILURE); }
fgets(buf, BUFLEN, stat);
numfields = strsplit (buf, fields, 9); if (numfields < 5) { fprintf(stderr, "To few fields\n"); exit(EXIT_FAILURE); }