5 Types of I/O models

Source: Internet
Author: User
Tags posix signal handler

There are 5 types of I/O models in the 1.Unix environment:

Blocking I/O, non-blocking I/O, signal-driven I/O (select and (e) poll), I/O multiplexing (select and (e) poll), asynchronous I/O (posix.1 aio_ series functions).

2. A single I/O is divided into two processes:

A. etc.

B. Data relocation

3. A detailed introduction < image of the fishing metaphor >

(1) Blocking I/O

First, the application calls an IO function, causing the application to block until the data is ready. If the data is ready, copy it from the kernel to the user space. If you are not ready, wait all the time.

Like a person fishing, when no fish hooked, sitting on the shore has been waiting.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/EB/wKiom1dEahzDVwZGAAC8eqOgxZI986.png "title=" 0.PNG " alt= "Wkiom1deahzdvwzgaac8eqogxzi986.png"/>

(2) Non-blocking I/O

Unlike (1), when the data is not ready, do not sleep the process, but return an error. Test so repeatedly until the data is ready. The amount of CPU time is consumed during the test.

Like a person in the fishing, not sitting on the shore do nothing, has been silly, but, while the head to play mobile phones, while looking up to see whether fish have hooked.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/E8/wKioL1dEUMbhbZpEAAFgdJsciCk046.png "title=" 3.PNG " alt= "Wkiol1deumbhbzpeaafgdjscick046.png"/>

(3) Signal-driven I/O (select and (e) poll)

We allow the socket interface to drive the signal-driven I/O and install a signal processing function that runs without blocking, and when the data is ready, the process receives a sigio signal that can invoke I/O in the signal handler function.

Like a wise man, who did not want to stare at the fishing rod, he fastened a bell on the rod, and when the bell rang, it was tantamount to telling him a signal that the fish had been hooked.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/EA/wKiom1dEURux7Nc4AAEDQTbOcNk926.png "title=" Capture 5. PNG "alt=" Wkiom1deurux7nc4aaedqtbocnk926.png "/>

(4) I/O multiplexing (select and (e) poll)

This model invokes the Select or poll function, which causes the process to block, but unlike blocking I/O, the two functions can block multiple I/O operations at the same time, and can detect multiple read operations, write I/O functions at the same time, and then invoke I/O operation functions until there is data readable and writable

It's like a man with a lot of fishing rods fishing, patrolling the shore, and pick up the rod when hooked.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/80/EA/wKiom1dEUyPQjfS8AAE-EKeINVQ865.png "title=" 6.PNG " alt= "Wkiom1deuypqjfs8aae-ekeinvq865.png"/>

(5) asynchronous I/O (posix.1 aio_ series functions)

Call the Aio_read function to tell the kernel descriptor, buffer pointer, size of buffers, file offset, and how to notify, and then immediately return. Notifies the application when the kernel copies the data to the buffer.

Just as one person hires another to fish, the other needs to tell him whether or not he is fishing, and he doesn't need to know the process.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/EB/wKiom1dEZ0yj6ZoPAAEjdbNkV-o949.png "title=" Capture 3. PNG "alt=" Wkiom1dez0yj6zopaaejdbnkv-o949.png "/>

4. Comparison of several I/O models

(1) The first four models: all synchronized. The first to second phase is basically the same, which copies the data from the kernel to the caller's buffer. The difference is different in the way.

(2) The two phases of asynchronous I/O are different from the first four models.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/80/E9/wKioL1dEaFDTggmaAAEdJkz1doQ669.png "title=" Capture 1. PNG "alt=" Wkiol1deafdtggmaaaedjkz1doq669.png "/>

This article is from the "sunshine225" blog, make sure to keep this source http://10707460.blog.51cto.com/10697460/1782731

5 Types of I/O models

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.