The difference between blocking vs non-blocking and synchronous vs asynchronous I/O comes down to two separate questions: whether a call waits when I/O cannot proceed yet, and whether the call itself performs the I/O and returns the result or submits a request whose completion is collected later. Based on the Linux manual pages (pipe(7), read(2), epoll(7), io_uring(7)), official Linux kernel documentation, and four C programs run in this post’s environment (x86-64 Linux, gcc 14.2, liburing 2.9, strace 6.13), this post compares how each model behaves on a real pipe.
Key Takeaways
Consistent with the Linux manual pages, this post organizes I/O along two axes. Blocking vs non-blocking describes whether a call waits when the I/O cannot proceed yet (a default read(2) on an empty pipe blocks; with O_NONBLOCK it returns -1 and EAGAIN at once). Synchronous vs asynchronous describes whether the call itself does the I/O and hands back the result when it returns (read(2), even with O_NONBLOCK, is synchronous) or a request is submitted first and its completion is collected later (io_uring). epoll is readiness notification: epoll_wait(2) waits (blocks) until a file descriptor is ready, and then the program performs an ordinary read(2) itself. Therefore, “non-blocking” is not the same thing as “asynchronous”.
Are blocking/non-blocking and sync/async the same thing?
One-line answer: No. Blocking vs non-blocking is about whether a call waits when I/O cannot proceed immediately, whereas sync vs async is about whether the call itself performs the I/O and returns the result or separates request submission from completion collection.
Waiting behavior (blocking/non-blocking) vs result delivery (sync/async)
To keep the terminology aligned with the Linux manual pages, this post separates the two axes as follows:
-
Blocking vs non-blocking (whether the call waits): What happens when the I/O operation cannot proceed right away. As documented in
pipe(7)andread(2), callingread(2)on an empty pipe blocks until data is available, whereas enablingO_NONBLOCKmakes the call return-1withEAGAINimmediately without waiting. -
Synchronous vs asynchronous (how the I/O is carried out and completed): Whether the call itself performs the I/O and hands back the result upon return, or whether the program submits a request and collects its completion later. Even with
O_NONBLOCKenabled,read(2)is synchronous because when data is available, theread(2)call itself copies the bytes and returns the count. By contrast,io_uring(7)is an asynchronous I/O API where requests are placed into a submission queue (SQ) and completions are collected from a completion queue (CQ).
Why are non-blocking and asynchronous often mixed up?
Many event-driven programs combine O_NONBLOCK file descriptors with epoll(7), which leads people to call the whole pattern “asynchronous”. However, as epoll(7) explains, epoll monitors file descriptors to see whether I/O is possible on any of them—that is readiness notification. When no events are currently available, epoll_wait(2) blocks the calling thread until a watched descriptor becomes ready (such as EPOLLIN), and then the user program still calls read(2) itself to transfer the data. Submitting an I/O operation to the kernel and collecting a completion event later, as in io_uring, is a distinct mechanism.

How does a blocking read wait inside the kernel?
One-line answer: Calling read(2) on an empty pipe blocks inside the kernel until data arrives; in the general pattern described by the kernel documentation, a .read handler puts the caller to sleep on a wait queue and wakes it with wake_up() when data is available.
Running read() on an empty pipe and checking strace
According to the “I/O on pipes and FIFOs” section of pipe(7), if a process attempts to read from an empty pipe, read(2) will block until data is available (and if a process attempts to write to a full pipe, write(2) blocks until sufficient data has been read from the pipe to allow the write to complete). In blocking_read.c below, the parent immediately calls read() on an empty pipe while the child writes "hello" after a moment:
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void) {
int fds[2];
char buf[16];
pipe(fds);
if (fork() == 0) { /* child: write after 1 second */
sleep(1);
write(fds[1], "hello", 5);
_exit(0);
}
printf("parent: calling read() on an empty pipe\n");
fflush(stdout);
ssize_t n = read(fds[0], buf, sizeof buf); /* blocks until data arrives */
printf("parent: read() returned %zd: %.*s\n", n, (int)n, buf);
wait(NULL);
return 0;
}
Built with gcc -O0 -Wall -o blocking_read blocking_read.c (with no warnings) and run in this post’s environment (x86-64 Linux, gcc 14.2, liburing 2.9, strace 6.13), ./blocking_read produces:
parent: calling read() on an empty pipe
parent: read() returned 5: hello
Here is the excerpt from strace -f -e signal=none -e trace=read,write ./blocking_read (the dynamic loader’s library read line is omitted, and because standard output was redirected to /dev/null under strace, final write(1, ...) lines can appear buffered):
365189 write(1, "parent: calling read() on an emp"..., 40) = 40
365189 read(3, <unfinished ...>
365190 write(4, "hello", 5) = 5
365190 +++ exited with 0 +++
365189 <... read resumed>"hello", 16) = 5
365189 write(1, "parent: read() returned 5: hello"..., 33) = 33
365189 +++ exited with 0 +++
In the trace, the parent’s read(3, <unfinished ...> (PID 365189) waits inside the kernel until the child (PID 365190) executes write(4, "hello", 5) = 5, after which <... read resumed>"hello", 16) = 5 completes and returns the 5 bytes. For background on tracing system calls this way, see strace: how to see which system calls a process makes (Korean).
How VFS .read and wait queues work
How a user-space system call enters the kernel and reaches a file or driver operation is covered in “How does a user program call the kernel? The svc/syscall, ioctl and copy_from_user flow”. According to the Linux kernel Virtual File System (VFS) documentation, the .read member of struct file_operations is called by read(2) and related system calls.
No kernel module was built or run for this post; what happens inside the kernel is explained from the official kernel documentation (“Unreliable Guide To Hacking The Linux Kernel”, section “Wait Queues include/linux/wait.h”). As that guide explains, a wait queue is used to wait for someone to wake you up when a certain condition is true, and must be used carefully to ensure there is no race condition:
-
A wait queue head (
wait_queue_head_t) is declared withDECLARE_WAIT_QUEUE_HEAD()or initialized withinit_waitqueue_head(). -
Waiting processes place a
wait_queue_entry_tin the queue, and must put themselves in the queue before checking the condition. -
wait_event_interruptible()returns0when the condition expression is true or-ERESTARTSYSif a signal is received, whereaswait_event()ignores signals. -
wake_up()wakes every process in the queue (except for exclusive waiters).
Putting those documented pieces together, the general pattern inside the kernel is that a .read implementation can put the caller to sleep on a wait queue until data arrives and is woken with wake_up()—which is what a blocking read(2) looks like from the kernel side.
What changes when O_NONBLOCK is enabled?
One-line answer: Enabling the O_NONBLOCK flag via fcntl(2) F_SETFL makes read(2) on an empty pipe return -1 with EAGAIN at once instead of waiting, while a read when data is present still completes synchronously during the call.
Setting O_NONBLOCK and observing EAGAIN
As pipe(7) documents, non-blocking I/O is enabled by using the fcntl(2) F_SETFL operation to set the O_NONBLOCK open file status flag (or by opening a fifo(7) with O_NONBLOCK). If any process has the pipe open for writing, reads on an empty pipe fail with EAGAIN; otherwise—with no potential writers—reads succeed and return empty (0). The ERRORS section of read(2) likewise states that EAGAIN is returned when the file descriptor refers to a file other than a socket, has been marked non-blocking (O_NONBLOCK), and the read would block (for sockets, EAGAIN or EWOULDBLOCK).
In nonblock_read.c below, the program enables O_NONBLOCK on the read end of the pipe, calls read() once while the pipe is empty, writes "hello", and calls read() a second time:
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void) {
int fds[2];
char buf[16];
pipe(fds);
fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
ssize_t n = read(fds[0], buf, sizeof buf); /* empty pipe: returns at once */
printf("1st read: %zd, errno=%s\n", n, n < 0 ? strerror(errno) : "-");
printf("EAGAIN? %s\n", (n < 0 && errno == EAGAIN) ? "yes" : "no");
write(fds[1], "hello", 5);
n = read(fds[0], buf, sizeof buf);
printf("2nd read: %zd: %.*s\n", n, (int)n, buf);
return 0;
}
Built with gcc -O0 -Wall -o nonblock_read nonblock_read.c and run, ./nonblock_read prints:
1st read: -1, errno=Resource temporarily unavailable
EAGAIN? yes
2nd read: 5: hello
Here is the trace from strace -e trace=read,write,fcntl ./nonblock_read (the dynamic loader’s library read line is omitted, and stdout redirection combines the final output into a single write(1, ...) call):
fcntl(3, F_GETFL) = 0 (flags O_RDONLY)
fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
read(3, 0x7fffcfd05cc0, 16) = -1 EAGAIN (Resource temporarily unavailable)
write(4, "hello", 5) = 5
read(3, "hello", 16) = 5
write(1, "1st read: -1, errno=Resource tem"..., 84) = 84
+++ exited with 0 +++
Why non-blocking read is still synchronous
Right after fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0, the first read(3, ...) returns -1 EAGAIN immediately instead of sleeping—that is the non-blocking behavior. Once write(4, "hello", 5) = 5 puts data into the pipe, the second call read(3, "hello", 16) = 5 performs the read during the system call and returns 5 with the buffer filled. Because the call itself does the I/O and hands back the result upon return, a non-blocking read(2) is still synchronous.
Is epoll non-blocking or asynchronous?
One-line answer: epoll is a readiness notification mechanism rather than asynchronous I/O: epoll_wait(2) waits (blocks) until a watched file descriptor can perform I/O, and the program then calls read(2) itself.
Interest list, ready list, and VFS .poll
According to epoll(7), the epoll API performs a similar task to poll(2): monitoring multiple file descriptors to see if I/O is possible on any of them. It can operate in level-triggered or edge-triggered mode and scales well to large numbers of watched file descriptors:
-
epoll_create1(2)creates anepollinstance. -
An
epollinstance holds an interest list (file descriptors registered viaepoll_ctl(2)) and a ready list that is “dynamically populated by the kernel as a result of I/O activity”. -
epoll_wait(2)waits for I/O events, blocking the calling thread if no events are currently available.
In the kernel VFS documentation, the .poll method of struct file_operations is described as the function called by the VFS when a process wants to check if there is activity on the file and optionally go to sleep until there is activity (used by system calls such as select(2) and poll(2)). Waiting for an event notification instead of repeatedly checking status is a related idea at the hardware level in Interrupts vs polling (Korean).
Running epoll_pipe.c and tracing with strace
In epoll_pipe.c below, the read end of the pipe is marked O_NONBLOCK and registered on an epoll instance for EPOLLIN; the parent waits in epoll_wait() while the child writes "hello" after a moment:
#include <fcntl.h>
#include <stdio.h>
#include <sys/epoll.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void) {
int fds[2];
char buf[16];
pipe(fds);
fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
int ep = epoll_create1(0);
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fds[0] };
epoll_ctl(ep, EPOLL_CTL_ADD, fds[0], &ev);
if (fork() == 0) { /* child: write after 1 second */
sleep(1);
write(fds[1], "hello", 5);
_exit(0);
}
struct epoll_event out;
printf("waiting in epoll_wait()\n");
fflush(stdout);
int r = epoll_wait(ep, &out, 1, -1); /* sleeps until the fd is readable */
printf("epoll_wait returned %d, EPOLLIN=%s, fd=%d\n",
r, (out.events & EPOLLIN) ? "yes" : "no", out.data.fd);
ssize_t n = read(fds[0], buf, sizeof buf);
printf("read: %zd: %.*s\n", n, (int)n, buf);
wait(NULL);
return 0;
}
Built with gcc -O0 -Wall -o epoll_pipe epoll_pipe.c and run, ./epoll_pipe outputs:
waiting in epoll_wait()
epoll_wait returned 1, EPOLLIN=yes, fd=3
read: 5: hello
Here is the excerpt from strace -f -e signal=none -e trace=epoll_create1,epoll_ctl,epoll_wait,read,write ./epoll_pipe (the dynamic loader’s library read line is omitted):
365207 epoll_create1(0) = 5
365207 epoll_ctl(5, EPOLL_CTL_ADD, 3, {events=EPOLLIN, data=0x3}) = 0
365207 write(1, "waiting in epoll_wait()\n", 24) = 24
365207 epoll_wait(5, <unfinished ...>
365208 write(4, "hello", 5) = 5
365207 <... epoll_wait resumed>[{events=EPOLLIN, data=0x3}], 1, -1) = 1
365207 read(3, "hello", 16) = 5
365208 +++ exited with 0 +++
365207 write(1, "epoll_wait returned 1, EPOLLIN=y"..., 56) = 56
365207 +++ exited with 0 +++
In the trace, epoll_wait(5, <unfinished ...> blocks until the child writes "hello", then resumes and returns 1 with EPOLLIN on file descriptor 3. After that, the parent process itself calls read(3, "hello", 16) = 5. In other words, epoll notified the program that the descriptor was ready, and the read was still performed synchronously by the program.
What makes io_uring asynchronous?
One-line answer: io_uring is asynchronous because user space submits I/O requests as submission queue entries (SQEs) in a shared submission queue (SQ) and collects their results later as completion queue events (CQEs) from a shared completion queue (CQ).
Submission queue (SQ) and completion queue (CQ) architecture
According to io_uring(7), io_uring is a Linux-specific API for asynchronous I/O that allows the user to submit one or more I/O requests, which are processed asynchronously without blocking the calling process:
-
Using
io_uring_setup(2)andmmap(2), user space and kernel space share two ring buffers: the submission queue (SQ) and the completion queue (CQ). -
Each request is a submission queue entry (SQE) with an opcode such as
IORING_OP_READ(corresponding toread(2)). -
After adding SQEs, calling
io_uring_enter(2)tells the kernel to begin processing them;io_uring_enter(2)can optionally also wait for a number of completions. -
The kernel places exactly one completion queue event (CQE) into the CQ per SQE. The CQE’s
resfield holds what the equivalent system call would have returned, or-errnoon error (errnoitself is never used).
The program below uses the liburing helper library (io_uring_queue_init, io_uring_get_sqe, io_uring_prep_read, io_uring_submit, io_uring_peek_cqe, io_uring_wait_cqe, io_uring_cqe_seen, io_uring_queue_exit).
Running uring_read.c and examining strace
In uring_read.c below, the program submits a read request (with user_data = 42) on an empty pipe before any data exists, peeks at the completion queue once, writes "hello" to the pipe, and then collects the completion:
#include <liburing.h>
#include <stdio.h>
#include <unistd.h>
int main(void) {
struct io_uring ring;
int fds[2];
char buf[16];
pipe(fds);
if (io_uring_queue_init(4, &ring, 0) < 0) { printf("io_uring_queue_init failed\n"); return 1; }
struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fds[0], buf, sizeof buf, 0); /* ask the kernel to read */
sqe->user_data = 42;
int s = io_uring_submit(&ring);
printf("submitted %d request(s); no data in the pipe yet\n", s);
struct io_uring_cqe *cqe;
printf("peek before write: %s\n",
io_uring_peek_cqe(&ring, &cqe) == 0 ? "completed" : "not completed yet");
write(fds[1], "hello", 5); /* data arrives later */
io_uring_wait_cqe(&ring, &cqe); /* collect the completion */
printf("completion: user_data=%llu res=%d data=%.*s\n",
(unsigned long long)cqe->user_data, cqe->res, cqe->res, buf);
io_uring_cqe_seen(&ring, cqe);
io_uring_queue_exit(&ring);
return 0;
}
Built with gcc -O0 -Wall -o uring_read uring_read.c -luring (no warnings) and run, ./uring_read prints:
submitted 1 request(s); no data in the pipe yet
peek before write: not completed yet
completion: user_data=42 res=5 data=hello
Here is the excerpt from strace -e trace=io_uring_setup,io_uring_enter,write,read ./uring_read (the dynamic loader’s library read line is omitted):
io_uring_setup(4, {flags=IORING_SETUP_NO_SQARRAY, sq_thread_cpu=0, sq_thread_idle=0, sq_entries=4, cq_entries=8, features=IORING_FEAT_SINGLE_MMAP|IORING_FEAT_NODROP|IORING_FEAT_SUBMIT_STABLE|IORING_FEAT_RW_CUR_POS|IORING_FEAT_CUR_PERSONALITY|IORING_FEAT_FAST_POLL|IORING_FEAT_POLL_32BITS|IORING_FEAT_SQPOLL_NONFIXED|IORING_FEAT_EXT_ARG|IORING_FEAT_NATIVE_WORKERS|IORING_FEAT_RSRC_TAGS|IORING_FEAT_CQE_SKIP|IORING_FEAT_LINKED_FILE|IORING_FEAT_REG_REG_RING|IORING_FEAT_RECVSEND_BUNDLE|IORING_FEAT_MIN_TIMEOUT, sq_off={head=0, tail=4, ring_mask=16, ring_entries=24, flags=36, dropped=32, array=0, user_addr=0}, cq_off={head=8, tail=12, ring_mask=20, ring_entries=28, overflow=44, cqes=64, flags=40, user_addr=0}}) = 5
io_uring_enter(5, 1, 0, 0, NULL, 8) = 1
write(4, "hello", 5) = 5
write(1, "submitted 1 request(s); no data "..., 127) = 127
+++ exited with 0 +++
The read request was submitted via io_uring_enter(5, 1, 0, 0, NULL, 8) = 1 before any data was in the pipe, and io_uring_peek_cqe reported not completed yet. After write(4, "hello", 5) = 5 wrote the data, the completion event arrived with user_data=42, res=5, and buf containing hello—without the program calling read(3, ...) on the pipe. In this run, strace also showed only the single io_uring_enter call used to submit the request and no second io_uring_enter while waiting; the completion was collected from the shared-memory completion queue (CQ) ring.

Which approach fits each situation?
One-line answer: The four examples differ in whether the call waits when the pipe is empty, who performs the read, and how completion is observed, so you pick the model that matches how your program coordinates I/O.
Comparison table of the four pipe-reading examples
The table below summarizes the four programs using only the behaviors observed above:
| Example / Call | Waits when pipe is empty? | Who performs the I/O (read)? | How you learn it finished |
|---|---|---|---|
blocking_read.c (default read(2)) | read(2) blocks inside the kernel until data arrives | The read(2) system call itself | read(2) returns the byte count (5) |
nonblock_read.c (O_NONBLOCK + read(2)) | Does not wait; returns -1 (EAGAIN) at once | The read(2) call itself, once data is present | The succeeding read(2) returns the byte count (5) |
epoll_pipe.c (epoll_wait(2) + read(2)) | epoll_wait(2) blocks until the descriptor is ready | The program calls read(2) itself after readiness notification | epoll_wait(2) reports EPOLLIN, then read(2) returns the byte count |
uring_read.c (io_uring SQ/CQ) | Submitting the SQE returns before data exists (waiting for CQE is separate) | The kernel processes the submitted IORING_OP_READ SQE asynchronously | Collected from the CQ as a CQE with res=5 and user_data=42 |
-
When a single call can simply sleep until data arrives, a default blocking
read(2)does the job directly. -
When a call on an empty descriptor must return right away with
EAGAINinstead of putting the thread to sleep, enableO_NONBLOCK. -
When monitoring multiple file descriptors to find out which ones are ready before calling
read(2)yourself, combineepoll(7)withO_NONBLOCK. -
When you want to submit I/O requests and collect completions separately through shared submission and completion rings, use
io_uring(7).
What are the frequently asked questions?
One-line answer: Here are answers to three common questions about O_NONBLOCK read(2), reading from a pipe with no writers, and error reporting in io_uring.
Is read(2) with O_NONBLOCK asynchronous I/O?
No. With `O_NONBLOCK`, `read(2)` is non-blocking because it returns `-1` and `EAGAIN` immediately when no data is available, but it is still synchronous because when data is available, the `read(2)` call itself performs the read and returns the result.What does an O_NONBLOCK read(2) return when no process has the pipe open for writing?
According to `pipe(7)`, if any process has the pipe open for writing, a non-blocking read on an empty pipe fails with `EAGAIN`; otherwise—with no potential writers—the read succeeds and returns empty (`0`).How are errors reported in an io_uring completion queue event (CQE)?
According to `io_uring(7)`, `errno` is never used; instead, the CQE's `res` field holds what the equivalent system call would have returned, and on error it holds `-errno`.What related posts are worth reading?
One-line answer: These related posts cover tracing system calls with strace, interrupts vs polling at the hardware level, and how a user-space call enters the kernel.
-
strace: how to see which system calls a process makes (Korean)
-
“How does a user program call the kernel? The svc/syscall, ioctl and copy_from_user flow”
What are the sources?
One-line answer: Below are the four Linux manual pages and two official Linux kernel documentation pages referenced in this post.
-
pipe(7) — Linux manual page (checked 2026-11-04)
-
read(2) — Linux manual page (checked 2026-11-04)
-
epoll(7) — Linux manual page (checked 2026-11-04)
-
io_uring(7) — Linux manual page (checked 2026-11-04)
-
Linux kernel docs: Unreliable Guide To Hacking The Linux Kernel (Wait Queues) (checked 2026-11-04)
-
Linux kernel docs: Overview of the Linux Virtual File System (checked 2026-11-04)