Five types of I/O models under Linux

Source: Internet
Author: User

Blocking I/O (blocking I/O)

Non-blocking I/O (nonblocking I/O)

I/O multiplexing (SELECT and poll) (I/O multiplexing)

Signal-driven I/O (signal driven I/O (SIGIO))

asynchronous I/O (asynchronous I/O (the POSIX aio_functions))

The first four types are synchronous, and only the last is asynchronous IO.


The I/O process is divided into two processes, data preparation and data copying


Blocking I/O model:

The model is blocked in two processes until the data copy is complete and the system call returns.

Block I/O model diagram:


when the recv () function is called, the system first checks to see if there is ready data. If the data is not ready, then the system is in a wait state. When the data is ready, the data is copied from the system buffer to the user space, and then the function returns. In a socket application, when the recv () function is called, the data is not necessarily present in the user space, then the recv () function is in a wait state.

non-blocking IO model non-blocking I/O makes multiple calls to a system call (if the data is not ready) in the first procedure and returns immediately. During the data copy process, it is still blocked.        

We set a socket interface to non-blocking to tell the kernel that when the requested I/O operation cannot be completed, do not sleep the process, but return an error. This way our I/O operations function will constantly test whether the data is ready, and if not, continue testing until the data is ready. In this ongoing testing process, it consumes a lot of CPU time. Sort of like polling

Non- Block I/O model diagram:



IO multiplexing Model:

I/O multiplexing models commonly used functions have Select, poll and Epoll, the specific differences please consult the relevant information. These functions also cause the process to be blocked (note that it is distinguished from I/O blocking) that the function can listen on multiple sockets to see if a socket is ready, return a ready socket if it is ready (or return time-out), and then follow the corresponding ready event for the ready socket (reading data or writing data)

I/O multiplexing Model diagram:


Signal-driven IO

First we allow the socket interface to drive the signal-driven I/O and install a signal processing function, and the process continues to run without blocking. When the data is ready, the process receives a sigio signal, and we can call the I/O operation function in the signal processing function to process the data.


Asynchronous IO ModelNo blocking occurs in two processes until a copy of the data is completed and a notification is received.

When an asynchronous procedure call is made, the caller cannot get the result immediately. The module that actually processes the call notifies the caller through a state or callback after the I/O operation is completed



The difference between synchronous IO and asynchronous IO: When the data is copied, the process is blocked!

the difference between blocking IO and non-blocking IO: during data preparation, the process is blocked !



Comparison of 5 I/O Models:





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Five types of I/O models under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.