There are five I/O models in UNIX
Blocking I/O
Non-blocking I/O
I/O multiplexing (select and poll)
Signal-driven I/O (sigio)
Asynchronous I/O (posix.1 AIO _ series functions)
B. Block I/O models
An application calls an I/O function, leading to application blocking and waiting for data preparation.
If the data is not ready, keep waiting ....
The data is ready. copy the data from the kernel to the user space.
Io function return success indicator
C. Non-blocking I/O model
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.
D. I/O Reuse Model
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.
E. Signal-driven I/O model
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.
F. asynchronous I/O model
Call the aio_read function to tell the kernel description, buffer pointer, buffer size, file offset, and notification method, and then return immediately. When the kernel copies the data to the buffer, it notifies the application.
2. Comparison of several I/O models
The difference between the first four models is that the first stage is basically the same, and the second stage is basically the same. Data is copied from the kernel to the caller's buffer zone. The two phases of asynchronous I/O are different from the first four models.
3. synchronous I/O and asynchronous I/O
A. synchronous I/O operations cause request process blocking until I/O operations are completed.
Asynchronous I/O operations do not cause request process blocking.
B. Our first four models are synchronous I/O, and only the last asynchronous I/O model is asynchronous I/O.