From 4cb62617fbc1c9c9ad454c1b18a313ca5e7b744e Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 30 Oct 2014 16:34:36 -0400 Subject: [PATCH 1/1] fix blocking call in signal handler, switch to CPU nanosecond time --- assgn7/timer.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/assgn7/timer.c b/assgn7/timer.c index 6d35ff5..c8fef98 100644 --- a/assgn7/timer.c +++ b/assgn7/timer.c @@ -10,31 +10,29 @@ int done; void handle_start() { - if(clock_gettime(CLOCK_MONOTONIC, start_time) == -1) { + if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, start_time) == -1) { printf("failed to get start time.\n"); exit(1); } - - pause(); } void handle_stop() { long int start_sec, stop_sec, delta; - if(clock_gettime(CLOCK_MONOTONIC, stop_time) == -1) { + if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, stop_time) == -1) { printf("failed to get stop time.\n"); exit(1); } - start_sec = ((long int) start_time->tv_sec); - stop_sec = ((long int) stop_time->tv_sec); + start_sec = ((long int) start_time->tv_nsec); + stop_sec = ((long int) stop_time->tv_nsec); delta = stop_sec - start_sec; - printf("%ld seconds elapsed between signals.\n", delta); + printf("%ld nanoseconds elapsed between signals.\n", delta); done = 1; } @@ -58,7 +56,7 @@ int main(int argc, char *argv[]) { pause(); if(!done) - goto terminate_check; + goto terminate_check; /* sorry */ free(start_time); free(stop_time); -- 2.41.0