Home

Kevent

Kevent is part of the kqueue event notification subsystem used in BSD-derived operating systems, notably FreeBSD and macOS. It provides a scalable, event-driven model for monitoring a variety of sources, including file descriptors, file system changes, timers, signals, processes, and user-defined events. A program typically creates a kqueue instance and then registers interest in certain event sources, after which it receives notifications when those events become ready.

The core API consists of two parts: kqueue() and kevent(). The kqueue() function creates a new kernel

A kevent is described by a struct containing several fields: ident identifies the event source (such as

Common use cases include asynchronous I/O, scalable servers, filesystem monitoring, timers, and signal handling. The system

event
queue
and
returns
a
descriptor
used
in
subsequent
calls.
The
kevent()
function
serves
both
to
register
or
modify
event
interests
and
to
retrieve
events
that
have
occurred.
It
accepts
arrays
of
struct
kevent
for
changes
and
for
returned
events,
enabling
batch
registration
and
single-shot
or
continuous
monitoring.
A
timeout
parameter
allows
blocking,
polling,
or
non-blocking
behavior.
a
file
descriptor
or
a
vnode);
filter
selects
the
event
type
(for
example
EVFILT_READ,
EVFILT_WRITE,
EVFILT_TIMER,
EVFILT_VNODE,
EVFILT_SIGNAL,
EVFILT_PROC,
EVFILT_USER);
flags
control
the
operation
(EV_ADD,
EV_DELETE,
EV_ENABLE,
EV_DISABLE,
EV_ONESHOT,
EV_CLEAR);
fflags
carry
filter-specific
options;
data
provides
auxiliary
information;
and
udata
is
a
user-defined
pointer
carried
through
to
the
event.
is
designed
for
high
performance
and
low
overhead
in
event-driven
applications,
and
remains
a
standard
facility
on
BSD-based
platforms.