//------------------------------------------------------------------- // nanowait.cpp // // This example shows the use of Linux's 'nanosleep()' function // for performing fine-grained time-delays in application code. // (Use your watch to check that the total delay is 5-seconds.) // // to compile: $ nanowait.cpp -o nanowait // to execute: $ ./nanowait // // programmer: ALLAN CRUSE // written on: 26 FEB 2009 //------------------------------------------------------------------- #include // for printf() #include // for nanosleep() struct timespec myts = { 0, 1000000 }; int main( int argc, char **argv ) { // try executing a delay of one-million nanoseconds, but // do it five thousand times (for a total of 5-seconds). for (int i = 0; i < 5000; i++) nanosleep( &myts, NULL ); printf( "Done\n" ); }