In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what are the five IO models in Linux, which have certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
We all know that everything in unix is a file, and what is a file? A file is a string of binary streams, whether socket, FIFO, pipeline, terminal, for us, everything is a file, everything is a stream, in the process of information exchange, we are all sending and receiving data to these streams, referred to as I/O operations (input and output), reading data into the stream, system call read, write data, system call write.
1. IO model
There are five IO models available under Linux:
blocking IO
nonblocking IO
IO multiplexing
Signal Driven IO (SIGIO)
Asynchronous IO (aio_series function of Posix)
Among them, except asynchronous IO, the rest belong to synchronous IO model. In these five models, we are currently only concerned with the first three, and IO multiplexing in the network programming topic, this article only briefly introduces the concept and difference between blocking IO and non-blocking IO.
2. blocking IO
Blocking IO is the most basic and commonly used IO model in Linux. It refers to functions that may block processes forever. It is generally expressed as:
A process or thread calls a function, which needs to meet certain conditions to execute downward. If the condition is not met, it will block the calling process or thread and give up CPU control until the condition is met. In Linux, blocking IO generally appears as a default attribute, such as mq_receive, sem_wait, sem_post, etc. By default, all sockets are blocked. We take UDP sockets as an example to show the blocking IO model, as shown in the following figure. The process calls recvfrom to receive data, but blocks because the kernel is not ready; the process does not unblock until the kernel is ready and recvfrom finishes copying the data.
3. nonblocking IO
As the name implies, non-blocking IO does not cause the calling process or thread to block forever, specifically: if the IO operation cannot complete, an error is immediately returned, and the calling process or thread continues to execute downward. For a given descriptor, there are two ways to designate it as non-blocking IO: Call open Specify the O_NONBLOCK flag when creating or opening a file For an already open descriptor, call fcntl Change its properties, setting the O_NONBLOCK flag for it
#includeint fcntl(int fd, int cmd, ... /* int arg */);
Set cmd to F_SETFL and arg to O_NONBLOCK to set the non-blocking flag for fd.
Thank you for reading this article carefully. I hope the article "What are the five IO models in Linux" shared by Xiaobian will be helpful to everyone. At the same time, I hope you will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.