fork download
  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. int n=0;
  7. timer_t timerid;
  8.  
  9. void beep(sigval_t sig)
  10. {
  11. struct itimerspec timeval;
  12.  
  13. printf("%d x %d = %d\n", n/8+2, n%8+2, (n/8+2)*(n%8+2));
  14. n++;
  15.  
  16. if (n>=64) {
  17. memset(&timeval, 0, sizeof(timeval));
  18. timer_settime(timerid, 0, &timeval, NULL);
  19. }
  20. }
  21.  
  22. int main(void)
  23. {
  24. struct sigevent sigev;
  25. struct itimerspec timeval;
  26. struct timespec ts;
  27.  
  28. memset(&sigev, 0, sizeof(sigev));
  29. sigev.sigev_notify = SIGEV_THREAD;
  30. sigev.sigev_notify_function = beep;
  31.  
  32. timeval.it_interval.tv_sec = 0;
  33. timeval.it_interval.tv_nsec = 100000000;
  34. timeval.it_value.tv_sec = 0;
  35. timeval.it_value.tv_nsec = 100000000;
  36.  
  37. timer_create(CLOCK_MONOTONIC, &sigev, &timerid);
  38. timer_settime(timerid, 0, &timeval, NULL);
  39.  
  40. ts.tv_sec = 7;
  41. ts.tv_nsec = 0;
  42. nanosleep(&ts, NULL);
  43.  
  44. timer_delete(timerid);
  45.  
  46. return 0;
  47. }
  48.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:7:1: error: unknown type name ‘timer_t’
 timer_t timerid;
 ^~~~~~~
prog.c:9:11: error: unknown type name ‘sigval_t’
 void beep(sigval_t sig)
           ^~~~~~~~
prog.c: In function ‘main’:
prog.c:24:26: error: storage size of ‘sigev’ isn’t known
         struct  sigevent sigev;
                          ^~~~~
prog.c:25:28: error: storage size of ‘timeval’ isn’t known
         struct  itimerspec timeval;
                            ^~~~~~~
prog.c:29:30: error: ‘SIGEV_THREAD’ undeclared (first use in this function)
         sigev.sigev_notify = SIGEV_THREAD;
                              ^~~~~~~~~~~~
prog.c:29:30: note: each undeclared identifier is reported only once for each function it appears in
prog.c:30:39: error: ‘beep’ undeclared (first use in this function)
         sigev.sigev_notify_function = beep;
                                       ^~~~
prog.c:37:9: warning: implicit declaration of function ‘timer_create’ [-Wimplicit-function-declaration]
         timer_create(CLOCK_MONOTONIC, &sigev, &timerid);
         ^~~~~~~~~~~~
prog.c:37:22: error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
         timer_create(CLOCK_MONOTONIC, &sigev, &timerid);
                      ^~~~~~~~~~~~~~~
prog.c:38:9: warning: implicit declaration of function ‘timer_settime’ [-Wimplicit-function-declaration]
         timer_settime(timerid, 0, &timeval, NULL);
         ^~~~~~~~~~~~~
prog.c:42:9: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
         nanosleep(&ts, NULL);
         ^~~~~~~~~
prog.c:44:9: warning: implicit declaration of function ‘timer_delete’ [-Wimplicit-function-declaration]
         timer_delete(timerid);
         ^~~~~~~~~~~~
prog.c:25:28: warning: unused variable ‘timeval’ [-Wunused-variable]
         struct  itimerspec timeval;
                            ^~~~~~~
prog.c:24:26: warning: unused variable ‘sigev’ [-Wunused-variable]
         struct  sigevent sigev;
                          ^~~~~
stdout
Standard output is empty