Created
March 7, 2021 16:20
-
-
Save kostikbel/ac6cba0501246a1c96ba4420a690dc3c 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 <sys/param.h> | |
#include <sys/event.h> | |
#include <err.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
int | |
main(void) | |
{ | |
struct kevent wev[1], rev[1]; | |
int error, kq; | |
kq = kqueue(); | |
if (kq == -1) | |
err(1, "kqueue"); | |
EV_SET(&wev[0], 1, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, 1, 0); | |
error = kevent(kq, wev, nitems(wev), NULL, 0, NULL); | |
if (error != 0) | |
err(1, "kevent register"); | |
while (true) { | |
error = kevent(kq, NULL, 0, rev, nitems(rev), NULL); | |
if (error < 0) | |
err(1, "kevent read"); | |
if (error == 0) | |
continue; | |
printf("event %p filt %d flag %x fflag %x data %jd\n", | |
(void *)rev[0].ident, rev[0].filter, rev[0].flags, | |
rev[0].fflags, (uintmax_t)rev[0].data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment