Back to index

glibc  2.9
clocktest.c
Go to the documentation of this file.
00001 #include <signal.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <time.h>
00005 #include <unistd.h>
00006 
00007 volatile int gotit = 0;
00008 
00009 static void
00010 alarm_handler (int signal)
00011 {
00012     gotit = 1;
00013 }
00014 
00015 
00016 int
00017 main (int argc, char ** argv)
00018 {
00019   clock_t start, stop;
00020 
00021   if (signal(SIGALRM, alarm_handler) == SIG_ERR)
00022     {
00023       perror ("signal");
00024       exit (1);
00025     }
00026   alarm(1);
00027   start = clock ();
00028   while (!gotit);
00029   stop = clock ();
00030 
00031   printf ("%ld clock ticks per second (start=%ld,stop=%ld)\n",
00032          stop - start, start, stop);
00033   printf ("CLOCKS_PER_SEC=%ld, sysconf(_SC_CLK_TCK)=%ld\n",
00034          CLOCKS_PER_SEC, sysconf(_SC_CLK_TCK));
00035   return 0;
00036 }