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
8volatile int gotit = 0;
9
10static void
11alarm_handler (int signal)
12{
13 gotit = 1;
14}
15
16
17int
18main (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

source code of glibc/time/clocktest.c