I'm trying to measure time between the moment process is waken up after thread blocking with clock_nanosleep and actual time it was waken up. Later on save the answers to array and with measurements print it to file but the problem is with making thread sleep.
for(i ; i < number_of_answers ; i++)
{
clock_gettime(CLOCK_MONOTONIC, &deadline);
deadline.tv_nsec += 250000;
if(deadline.tv_nsec >= 1000000000)
{
deadline.tv_nsec -= 1000000000;
deadline.tv_sec++;
}
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline, 0);
clock_gettime(CLOCK_MONOTONIC, &now);
exec_time = (now.tv_sec - deadline.tv_sec) * 1000000000 + (now.tv_nsec - deadline.tv_nsec);
table[i] = exec_time;
}
for(j ; j < number_of_answers ; j++)
{
/*fopen, not implemented*/
printf("table number: %i, value of table:%f\n", j, table[j]);
}
Can anyone suggest me what should I correct to make it work? The output is
table number: 0, value of table:-249600.000000
table number: 1, value of table:-249900.000000
table number: 2, value of table:-249800.000000
table number: 3, value of table:-249800.000000
table number: 4, value of table:-249800.000000
table number: 5, value of table:-249800.000000
table number: 6, value of table:-249800.000000
table number: 7, value of table:-249800.000000
table number: 8, value of table:-249800.000000
table number: 9, value of table:-249700.000000