Created
November 8, 2016 15:20
-
-
Save travispaul/09d27ad91540b8b8d7d301b4207ef1b2 to your computer and use it in GitHub Desktop.
Create timers (until you can't)
This file contains hidden or 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
// Example: | |
// cc -lrt timertest.c | |
// ./a.out 128 | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <signal.h> | |
#include <time.h> | |
int | |
main(int argc, char *argv[]) | |
{ | |
int timers = atoi(argv[1]); | |
timer_t *timerid; | |
struct sigevent *sev; | |
int i; | |
timerid = malloc((sizeof timerid) * timers); | |
sev = malloc((sizeof sev) * timers); | |
for (i = 0; i < timers; i++) { | |
sev[i].sigev_notify = SIGEV_SIGNAL; | |
sev[i].sigev_signo = SIGRTMIN; | |
sev[i].sigev_value.sival_ptr = &timerid[i]; | |
printf("timer_create: %d\n", i); | |
if (timer_create(CLOCK_MONOTONIC, &sev[i], &timerid[i]) == -1) { | |
fprintf(stderr, "timer_create: %d failed\n", i); | |
exit(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment