File names on various operating systems, including Windows and UNIX, may be used to access "special " files, which are actually devices. Sample reserved MS-DOS device names include AUX, CON, PRN, COM1, and LPT1. Device files on UNIX systems are used to apply access rights and to direct operations on the files to the appropriate device drivers.
...
In this example, the user can specify a locked device or a FIFO filenamefile name, causing the program to hang on the call to open().
...
POSIX defines the O_NONBLOCK flag to open() which will ensure ensures that delayed operations on the a file do does not hang the program.
When opening a FIFO with
O_RDONLYorO_WRONLYset: IfO_NONBLOCKis set:
An open() for reading only will return without delay. An open() for writing only will return an error if no process currently has the file open for reading.
IfO_NONBLOCKis clear:
An open() for reading only will block the calling thread until a thread opens the file for writing. An open() for writing only will block the calling thread until a thread opens the file for reading.When opening a block special or character special file that supports non-blocking opens:
IfO_NONBLOCKis set:
The open() function will return without blocking for the device to be ready or available. Subsequent behaviour of the device is device-specific.
IfO_NONBLOCKis clear:
The open() function will block the calling thread until the device is ready or available before returning.Otherwise, the behaviour of
O_NONBLOCKis unspecified.
...