Kqueue

Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 on July 2000, also supported in NetBSD, OpenBSD, DragonFly BSD, and macOS. Kqueue was originally authored in 2000 by Jonathan Lemon, then involved with the FreeBSD Core Team. Kqueue makes it possible for software like nginx to solve the c10k problem.
Kqueue provides efficient input and output event pipelines between the kernel and userland. Thus, it is possible to modify event filters as well as receive pending events while using only a single system call to codice_1 per main event loop iteration. This contrasts with older traditional polling system calls such as codice_2 and codice_3 which are less efficient, especially when polling for events on numerous file descriptors.
Kqueue not only handles file descriptor events but is also used for various other notifications such as file modification monitoring, signals, asynchronous I/O events (AIO), child process state change monitoring, and timers which support nanosecond resolution, furthermore kqueue provides a way to use user-defined events in addition to the ones provided by the kernel.
Some other operating systems which traditionally only supported codice_3 and codice_2 also currently provide more efficient polling alternatives, such as epoll on Linux and I/O completion ports on Windows and Solaris.
codice_6 is a user space implementation of codice_7, which translates calls to an operating system's native backend event mechanism.
API.
The function prototypes and types are found in codice_8.
int kqueue(void);
Creates a new kernel event queue and returns a descriptor.
int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout);
Used to register events with the queue, then wait for and return any pending events to the user. In contrast to epoll, kqueue uses the same function to register and wait for events, and multiple event sources may be registered and modified using a single call. The codice_9 array can be used to pass modifications (changing the type of events to wait for, register new event sources, etc.) to the event queue, which are applied before waiting for events begins. codice_10 is the size of the user supplied codice_11 array that is used to receive events from the event queue.
EV_SET(kev, ident, filter, flags, fflags, data, udata);
A macro that is used for convenient initialization of a codice_12 object.
See also.
OS-independent libraries with support for kqueue:
Kqueue equivalent for other platforms: