Skip to content

Instantly share code, notes, and snippets.

@kostikbel
Created March 7, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostikbel/ac6cba0501246a1c96ba4420a690dc3c to your computer and use it in GitHub Desktop.
Save kostikbel/ac6cba0501246a1c96ba4420a690dc3c to your computer and use it in GitHub Desktop.
#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