8 struct timespec
*start_time
, *stop_time
;
13 if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID
, start_time
) == -1) {
15 printf("failed to get start time.\n");
22 long int start_sec
, stop_sec
, delta
;
24 if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID
, stop_time
) == -1) {
26 printf("failed to get stop time.\n");
30 start_sec
= ((long int) start_time
->tv_nsec
);
31 stop_sec
= ((long int) stop_time
->tv_nsec
);
33 delta
= stop_sec
- start_sec
;
35 printf("%ld nanoseconds elapsed between signals.\n", delta
);
40 int main(int argc
, char *argv
[]) {
44 start_time
= (struct timespec
*) calloc(1, sizeof(struct timespec
));
45 stop_time
= (struct timespec
*) calloc(1, sizeof(struct timespec
));
47 if(signal(SIGTSTP
, handle_start
) == SIG_ERR
||
48 signal(SIGCONT
, handle_stop
) == SIG_ERR
) {
50 printf("could not bind signal handlers\n");
59 goto terminate_check
; /* sorry */