#include #include #include #include #include #include #include #define BUFFSIZE (128*1024) typedef unsigned long long jiff; int main() { static char buff[BUFFSIZE]; /* used in the procedures */ static int fd; jiff cuse; jiff cice; jiff csys; jiff cide; jiff ciow; jiff cxxx; jiff cyyy; jiff czzz; unsigned intr; const char* b=NULL; buff[BUFFSIZE-1] = 0; /* ensure null termination in buffer */ if (fd) { lseek(fd, 0L, SEEK_SET); }else{ fd = open("/proc/stat", O_RDONLY, 0); if(fd == -1) perror("/proc/stat"); } read(fd,buff,BUFFSIZE-1); intr = 0; ciow = 0; /* not separated out until the 2.5.41 kernel */ cxxx = 0; /* not separated out until the 2.6.0-test4 kernel */ cyyy = 0; /* not separated out until the 2.6.0-test4 kernel */ czzz = 0; /* not separated out until the 2.6.11 kernel */ b = strstr(buff, "cpu "); if (b) { sscanf(b, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &cuse, &cice, &csys, &cide, &ciow, &cxxx, &cyyy, &czzz); printf("%llu %llu %llu %llu %llu %llu %llu %llu\n",cuse,cice,csys,cide,ciow,cxxx,cyyy,czzz); return 0; } else { printf("strstr failed\n"); } }