There are five I/O models in Unix/Linux:
1) blocking I/O
2) non-blocking I/O
3) I/O multiplexing (select and poll)
4) signal-driven I/O (sigio)
5) asynchronous I/O (posix.1 AIO _ series functions)
These models sometimes make me confused. I will summarize and compare them today:
Blocking I/O:
ApplicationProgramCalling an IO function causes application blocking and waits for data to be ready. If the data is not ready, keep waiting .... The data is ready. copy the data from the kernel to the user space. The IO function returns a successful instruction.
Non-blocking I/O:
When we set a set of interfaces to non-blocking, we will tell the kernel that when the requested I/O operation cannot be completed, do not sleep the process, but return an error. In this way, our I/O operation functions will continuously test whether the data is ready. If not, continue the test until the data is ready. In this continuous testing process, it will take a lot of CPU time.
I/O multiplexing (select and poll ):
The I/O reuse model uses select or poll functions. These two functions can also block the process, but they are different from those that block I/O, these two functions can block Multiple I/O operations at the same time. In addition, I/O functions of multiple read operations and write operations can be detected at the same time. I/O operation functions can be called only when data is readable or writable.
Signal-driven I/O (sigio ):
First, we allow the set of interfaces for signal-driven I/O, and install a signal processing function, the process continues to run without blocking. When the data is ready, the process receives a sigio signal and can call the I/O operation function in the signal processing function to process the data.
Asynchronous I/O (posix.1 AIO _ series functions ):
When an asynchronous process is called, the caller cannot obtain the result immediately. After the call is completed, the caller's input and output operations are notified through status, notification, and callback.