what is the difference between blocking i/o and non blocking i/o in unix like system. Does any one explain these concepts with real time scenario. I already gone through the references which are in online and books. But, still Iam not able to understand the use of non- blocking i/o. Does any one summarize what did you know about this instead of specifying any theory concepts which are alread in somewhere.
-
1This is quite broad. If you don't understand textbooks, post a *specific* question about what you don't understand about it. – P.P Dec 01 '15 at 10:06
-
Possible duplicate of [Do my (begginer) understanding of blocking and non blocking io is correct?](http://stackoverflow.com/questions/17796685/do-my-begginer-understanding-of-blocking-and-non-blocking-io-is-correct) – rmunn Dec 01 '15 at 10:07
-
Also a possible duplicate of http://stackoverflow.com/questions/1241429/blocking-io-vs-non-blocking-io-looking-for-good-articles - the first answer is a very good explanation of the concept. – rmunn Dec 01 '15 at 10:09
2 Answers
Often one has a process that does more than one single task. Some of those tasks may depend on external data.
Now imagine one of those tasks has to listen to some client that might make a request and to handle that request. For this the process must open a socket and listen to requests. With a blocking socket the process would now hang until a request actually comes in. This means that all other tasks the process has to handle cannot be handled until a request comes in! With a non-blocking socket however the socket command returns immediately if no request is pending. So the process can handle other tasks and come back and check for client requests on a regular base.
The same applies to files being read as input, though not that frequent: if a file is read whilst another process still writes into it, then a blocking read access will hang. A non-blocking access again allows to do other stuff in the mean time and return to reading the file later or on a regular base. Very important for log file processing, for example. So files that always get stuff appended per definition.
Other approaches exists to handle this issue. But blocking and non-blocking modes for file-/socket operations are a practical thing to keep complexity low.

- 41,620
- 7
- 58
- 90
Roughly.
When you buy a new house to be constructed, you use a non-blocking behavior, you buy it and do not wait (non-block) in place until the end of the construction. You just continue to live your life, and sometimes later either the constructor calls you to tells you that your new house is ready (signal, interrupt - passive wait), or you call him regularly to get some information about the construction process (poll - active wait).
When you go to a restaurant, you use a blocking behavior, you make your command and then wait (block) until being served.
In general, when you need something because you can't go further without what you need, you use a blocking scenario. When you need something but can do something else if what you need is not available now, you use a non-blocking scenario.

- 34,548
- 4
- 48
- 69