#include #include /* runtime in microseconds */ #define RUNTIME 9000 int main( int argc, char** argv ) { unsigned long n=0; unsigned long t; struct timeval s, e; while ( 1 ) { /* work */ gettimeofday( &s, NULL ); do { n++; gettimeofday( &e, NULL ); t = (e.tv_sec-s.tv_sec)*1000000 +(e.tv_usec-s.tv_usec); } while ( t < RUNTIME ); /* sleep */ usleep( 0 ); } }