ArticleslgStudy

computer science

Kqueue

Kqueue is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Kqueue rather than just read about it. In short: Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 in 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.

Key takeaways

  • Kqueue belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Kqueue to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Kqueue from memory before moving on to harder problems.

Reference excerpt

Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 in 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. The term "kqueue" refers to its function as a "kernel event queue" 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 kevent(2) per main event loop iteration. This contrasts with older traditional polling system calls such as poll(2) and select(2) 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 select(2) and poll(2) also currently provide more efficient polling alternatives, such as epoll on Linux and I/O completion ports on Windows and Solaris. libkqueue is a user space implementation of kqueue(2), which translates calls to an operating system's native backend event mechanism.

API

The function prototypes and types are found in <sys/event.h>.

Creates a new kernel event queue and returns a descriptor.

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 changelist 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. nevents is the size of the user supplied eventlist array that is used to receive events from the event queue.

A macro that is used for convenient initialization of a struct kevent object.

See also

OS-independent libraries with support for kqueue:

libevent libuv Kqueue equivalent for other platforms:

on Solaris, Windows and AIX: I/O completion ports. Note that completion ports notify when a requested operation has completed, whereas kqueue can also notify when a file descriptor is ready to perform an I/O operation. on Linux: epoll system call has similar but not identical semantics. inotify is a Linux kernel subsystem that notices changes to the filesystem and reports those to applications.

References

External links kqueue(2) – FreeBSD System Calls Manual libbrb_core implements an abstraction for an event-oriented base, using kqueue() system call FreeBSD source code of the kqueue() system call OpenBSD source code of the kqueue() system call NetBSD source code of the kqueue() system call DragonFly BSD source code of the kqueue() system call

Worked examples

Example 1 — a first encounter with Kqueue

Start with the simplest possible case. Write down what Kqueue claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Kqueue before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Kqueue ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Kqueue

In research
Kqueue appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Kqueue in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Kqueue is common in secondary-school and first-year university syllabi. It links to neighbouring topics BSD software, DragonFly BSD, Events (computing), so understanding it makes those chapters shorter.
In everyday life
Look for Kqueue outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Kqueue” →

How to study Kqueue in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Kqueue means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Kqueue out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Kqueue in simple terms?

Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 in 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.

Why does Kqueue matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Kqueue?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Kqueue.

Tags

  • BSD software
  • DragonFly BSD
  • Events (computing)
  • FreeBSD
  • Input/output
  • MacOS
  • NetBSD
  • OpenBSD
  • Operating system APIs
  • Operating system technology
  • System calls

Keep exploring