Created
May 20, 2021 17:07
-
-
Save b4284/cb1bf564c78451fedaa51a336aff604b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <signal.h> | |
#include <time.h> | |
#include <stdio.h> | |
#include <signal.h> | |
void sh(int sig) | |
{ | |
for (double f = 0; f < 10; f += 0.5) { | |
printf(" f = %g\n", f); | |
usleep(100000); | |
} | |
} | |
void main() | |
{ | |
struct sigaction sa; | |
sigemptyset(&sa.sa_mask); | |
sa.sa_handler = &sh; | |
sa.sa_flags = 0; | |
int c = sigaction(SIGALRM, &sa, NULL); | |
printf("c = %d\n", c); | |
timer_t tt; | |
int a = timer_create(CLOCK_REALTIME, NULL, &tt); | |
printf("a = %d\n", a); | |
struct itimerspec it; | |
it.it_interval.tv_sec = 0; | |
it.it_interval.tv_nsec = 0; | |
it.it_value.tv_sec = 1; | |
it.it_value.tv_nsec = 0; | |
int b = timer_settime(tt, 0, &it, NULL); | |
printf("b = %d\n", b); | |
for (int i = 0; i < 20; i++) { | |
printf(" i = %d\n", i); | |
usleep(100000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Perl document says it's not okay to use sleep() and signals at the same time, because sleep() might be implemented with signals as well.