1 | #include <signal.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <time.h> |
5 | #include <unistd.h> |
6 | #include <stdint.h> |
7 | |
8 | volatile int gotit = 0; |
9 | |
10 | static void |
11 | alarm_handler (int signal) |
12 | { |
13 | gotit = 1; |
14 | } |
15 | |
16 | |
17 | int |
18 | main (int argc, char ** argv) |
19 | { |
20 | clock_t start, stop; |
21 | |
22 | if (signal(SIGALRM, handler: alarm_handler) == SIG_ERR) |
23 | { |
24 | perror ("signal"); |
25 | exit (1); |
26 | } |
27 | alarm(1); |
28 | start = clock (); |
29 | while (!gotit); |
30 | stop = clock (); |
31 | |
32 | printf (format: "%jd clock ticks per second (start=%jd,stop=%jd)\n", |
33 | (intmax_t) (stop - start), (intmax_t) start, (intmax_t) stop); |
34 | printf (format: "CLOCKS_PER_SEC=%jd, sysconf(_SC_CLK_TCK)=%ld\n", |
35 | (intmax_t) CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK)); |
36 | return 0; |
37 | } |
38 |