clocktest.c 625 B

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