Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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