Fundamentals 9 min read

Understanding Blocking, Non‑Blocking, I/O Multiplexing, and Asynchronous I/O in Linux Network Programming

This article explains the four main I/O models—blocking, non‑blocking, I/O multiplexing (select/epoll), and asynchronous I/O—in the context of Linux network programming, clarifying their mechanisms, differences, and when each model is appropriate.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Understanding Blocking, Non‑Blocking, I/O Multiplexing, and Asynchronous I/O in Linux Network Programming

The article examines synchronous and asynchronous I/O, as well as blocking and non‑blocking I/O, focusing on Linux network I/O. It references Richard Stevens' "UNIX® Network Programming" for detailed definitions.

Stevens identifies five I/O models; the article discusses four of them: blocking I/O, non‑blocking I/O, I/O multiplexing, and asynchronous I/O.

Blocking I/O : By default, sockets are blocking. A read (e.g., recvfrom ) causes the kernel to wait for data, block the process, copy data to user space, and then return.

Non‑blocking I/O : The socket is set to non‑blocking mode. If data is not ready, the read returns immediately with an error, allowing the process to continue and poll again later.

I/O Multiplexing (select/epoll): The process calls select (or epoll ) and blocks while the kernel monitors multiple sockets. When any socket becomes ready, select returns and the process reads the data.

Asynchronous I/O : Rarely used on Linux. After issuing an asynchronous read, the kernel immediately returns, and later notifies the process via a signal when the data is ready and copied.

The article concludes that blocking vs. non‑blocking differs in whether the process is blocked during the read system call, while synchronous vs. asynchronous differs in whether the process is blocked for the entire I/O operation. Non‑blocking and asynchronous I/O both avoid blocking the process, but asynchronous I/O removes the need for the process to poll or manually copy data.

Finally, a fishing‑rod analogy illustrates the four models: A (blocking), B (non‑blocking with status check), C (I/O multiplexing with multiple rods), and D (asynchronous with a helper).

LinuxNetwork ProgrammingNon-blocking I/OSystems Programmingasynchronous I/Oblocking I/OIO models
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.