#include #include #define LB_SIZE 80 int main(int argc, char *argv[]){ char repTypeName[16], reportType, c1,c2, lineBuf[80]; int interval, duration, iteration = 0; enum reportType {STANDARD, SHORT, LONG}; FILE *thisProcFile; struct timeval now; /* Determine report type */ reportType = STANDARD; strcpy(repTypeName,"Standard"); if(argc > 1){ sscanf(argv[1],"%c%c",&c1,&c2); if(c1 != '-'){ fprintf(stderr,"usage: ksamp [-s][-l int dur]\n"); exit(1); } if(c2 == 's'){ reportType = SHORT; strcpy(repTypeName,"Short"); } if(c2 == 'l'){ reportType = LONG; strcpy(repTypeName,"Long"); interval = atoi(argv[2]); duration = atoi(argv[3]); } } /* Get the current time */ gettimeofday(&now, NULL); printf("Status report type %s at %s \n", repTypeName,ctime(&(now.tv_sec))); thisProcFile = fopen("/proc/sys/kernel/hostname","r"); fgets(lineBuf, LB_SIZE+1,thisProcFile); printf("Machine hostname: %s",lineBuf); fclose(thisProcFile); thisProcFile = fopen("/proc/cpuinfo","r"); printf("cpu information: \n"); while ( fgets(lineBuf, LB_SIZE+1,thisProcFile) != 0) printf("%s",lineBuf); /* Code to read the relevant /proc files*/ while (iteration < duration){ sleep(interval); /* sampleLoadAvg(); */ iteration += interval; } exit(0); }