finished
This commit is contained in:
31
V2/diff.c
Normal file
31
V2/diff.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include<time.h>
|
||||||
|
#include<pthread.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct timespec time1, start, ende;
|
||||||
|
time1.tv_sec = 5;
|
||||||
|
time1.tv_nsec = 0;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||||
|
clock_nanosleep(CLOCK_MONOTONIC, 0, &time1, NULL);
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ende);
|
||||||
|
|
||||||
|
int nsec_difference = (int) ((ende.tv_nsec - start.tv_nsec)/1000);
|
||||||
|
|
||||||
|
|
||||||
|
//microseconds
|
||||||
|
|
||||||
|
int sec_difference = (int) (ende.tv_sec - start.tv_sec)*1000*1000;
|
||||||
|
int real_time_slept = sec_difference + nsec_difference;
|
||||||
|
|
||||||
|
int difference_real_set = real_time_slept - time1.tv_sec * 1000 * 1000;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("Real time slept: %d\n", real_time_slept);
|
||||||
|
printf("Difference Real time slept and actually sleep time: %d usec\n", difference_real_set);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user