//---------------------------------------------------------------- // showjifs.cpp // // This program repeatedly reads and prints the information // in our '/proc/jiffies' file for one-million repetitions. // In conjunction with the UNIX 'time' command, you can get // a close estimate of the rate at which 'jiffies' is being // incremented, by typing this: // // $ time showjifs // // programmer: ALLAN CRUSE // written on: 07 SEP 2004 //---------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit(), atoi() #include // for read(), close() #include // for strtok() char filename[] = "/proc/jiffies"; int main( void ) { int initial_jiffies = 0; int current_jiffies = 0; for (int i = 0; i < 1000000; i++) { // open the pseudo-file int fd = open( filename, O_RDONLY ); if ( fd < 0 ) { perror( filename ); exit(1); } // read the file's contents char buffer[ 256 ]; int nbytes = read( fd, buffer, sizeof( buffer ) ); if ( nbytes < 0 ) { perror( "read" ); exit(1); } // remember the first-time jiffies-value current_jiffies = atoi( buffer+8 ); if ( initial_jiffies == 0 ) initial_jiffies = current_jiffies; // replace the final '\n' with a null byte strtok( buffer, "\n" ); // print resulting string on current output-line printf( "\r%s ", buffer ); // close the pseudo-file close( fd ); } printf( "\ninitial-value=%d ", initial_jiffies ); printf( "final_value=%d ", current_jiffies ); printf( "difference=%d \n\n", current_jiffies - initial_jiffies ); }