I am learning about poll
, select
and similar functions and I am constantly bothered by the statement "would block" (which shows up both on the book I am reading about building drivers for Linux and also on the man pages of poll
and select
). I don't really get this. What would be blocked? The process which is reading/writing to a file descriptor? The reading/writing operation itself, in the sense that no other process would be able to read/write to that file when the current process is reading/writing on it?
I am sorry if this is a stupid question but I am having a difficult time finding the answer for this question anywhere.
Would block means that the process making the system call would block (wait) until the system call returns. For example, if you ask your program to read a file, after issuing the read command, your program will wait (block) until the operating system performs the read and returns the results to your program.
With regards to multiple programs accessing the same file, multiple processes can read the same file. However, you can (and usually will) have race conditions when one or more processes is writing to a file that has one or more processes reading the same file. In other words, blocking is with regards to a single process accessing a file, and gives no guarantees about the order of operations (e.g. reads and writes) between two processes accessing the same file. (I was thinking about files for some reason; the read/write characteristics of pipes and sockets differ significantly from those of files on a filesystem).