Linux IO Model

Source: Internet
Author: User

Overview I/O types: Synchronous and Asynchronous: synchronous, asyncrhonous

the focus is on the message notification mechanism
Synchronization: The call does not return immediately, but once returned, the final result can be returned;
Asynchronous: After the call is issued, the callee returns the message immediately, but returns the non-final result; The callee notifies the caller through the state, notification mechanism, or the callback function to process the result;

Blocking and non-blocking: block, Nonblock

Attention is the state of the call result (message, return value) when called

Blocking: The caller (the calling thread) is suspended until the call results are returned, and the caller is returned only after the result is obtained;
Non-blocking: The call does not block the current thread until the call results are returned;

Tell a Story
event : Boil water. appearance characters : you, kettle two (ordinary kettle, referred to as a kettle, electric kettle: Power indicator light on, water on, lights out and beep beep). 1. You put the kettle on the fire and conforming the water. (synchronous blocking) 2. You put the kettle on the fire, go to the living room to watch TV, and occasionally go to the kitchen to see if the water is open. (Synchronous non-blocking) 3. You use electric kettle to boil water, plug-in lights, water lights out and give a hint, halfway is not to go, conforming. (asynchronous blocking) 4. You think you are silly, then the electric kettle indicator light is on, go to the living room to watch TV, before the kettle rang no longer to see it, rang again to get the pot. (Asynchronous non-blocking) : The so-called synchronous asynchronous, just for the kettle . Ordinary kettle, synchronous, electric kettle, asynchronous. Although all can work, but the electric kettle can be finished after oneself, prompt you to open water. This is not an ordinary kettle. Synchronization can only allow callers to poll themselves (in case 2), causing you to be inefficient. the so-called blocking non-blocking, just for you . Conforming you, blocking, watching TV you, non-blocking. Situation 1 and situation 3 You are blocked, the daughter-in-law shout you do not know. Although the 3 electric kettle is asynchronous, it does not make much sense for you to conforming. So asynchronous is generally used in conjunction with non-blocking, in order to play an asynchronous effect.
5 IO Model under UNIX
    1. Blocking IO
    2. nonblocking IO
    3. IO multiplexing (IO multiplexing)
    4. Signal Driven IO (event-driven IO)
    5. Asyncrhonous io (Asynchronous IO)
A read operation:
    1. and other data are ready;
    2. Copying data from the kernel to the process;

PS: The process makes the system call Recvfrom, the kernel will data--> the kernel space--user space, the process is completed before returning recvfrom this instruction, the entire process is waiting state.

PS: Non-blocking IO: The kernel interacts with the process continuously, and the data returns an error when it is ready.

Ps:io multiplexing is blocking on select, not blocking on real IO system calls, such as Recvfrom.

PS: event-driven IO

Horizontal Trigger: Multiple returns

Edge Trigger: One return

PS: True asynchronous IO, process notification, continue execution without waiting, kernel finishes data--> kernel space--process space, and then notifies the process. The other 4 models are still blocking IO, and at least one of the processes is blocked.

Linux IO Model

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.