Skip to content

Event Loop

The event loop topic connects the userspace and kernel-side event-driven patterns used throughout this learning series.

In Linux, many event sources can be represented as file descriptors. Once an event source becomes an fd, it can be integrated into a single poll() or epoll() loop.

What This Topic Covers

Area Main Idea Related APIs
Readiness notification Wait until an fd can be read or written poll(), epoll_wait()
Scalable event loop Manage many fds in one loop epoll_create1(), epoll_ctl()
Timer events Convert timers into fd events timerfd_create(), timerfd_settime()
Signal events Convert signals into fd events sigprocmask(), signalfd()
Kernel driver readiness Allow drivers to wake userspace event loops .poll, poll_wait(), wake_up_interruptible()
Async notification Notify userspace using SIGIO .fasync, kill_fasync()
  1. Start with poll and select to understand readiness-based I/O.
  2. Move to epoll for scalable fd multiplexing.
  3. Add timerfd to integrate periodic or timeout events.
  4. Add signalfd to handle signals inside the event loop.
  5. Study eventfd for userspace/kernel or thread-to-thread event notification.
  6. Review fasync and SIGIO as an alternative async notification model.

Event-Driven Architecture

[event source]
[file descriptor]
epoll_wait()
read / write / handle event

Common Linux event sources:

  • TCP sockets
  • UNIX domain sockets
  • character devices
  • timerfd
  • signalfd
  • eventfd
  • message queues
  • input devices
  • IIO buffers