From: ian Date: Thu, 30 Oct 2014 20:34:36 +0000 (-0400) Subject: fix blocking call in signal handler, switch to CPU nanosecond time X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=assignments.git;a=commitdiff_plain;h=4cb62617fbc1c9c9ad454c1b18a313ca5e7b744e fix blocking call in signal handler, switch to CPU nanosecond time --- 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);