busy waiting - How can I write a C program to execute for a certain number of processor seconds? -


i need c program execute precise number of cpu seconds passed in parameter. need such program in order test code monitors process' cpu usage.

example:

busywait x 

should run x seconds on processor.

this c program wrote solve problem. continuously checks number of clock cycles until correct number of processor-seconds has been used.

#include <stdio.h> #include <time.h>  int main(int argc, char * argv[]) {      clock_t start, end;      double cpu_time_used;      int wait;       sscanf(argv[1], "%d", &wait);       start = clock();      end = clock();      while (((double) (end - start)) / clocks_per_sec < wait)      {           end = clock();      } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -