Non-Blocking I/O

A process is put to sleep when performing I/O for one or more of the following reasons:

  • A read request must wait for input data to arrive.

  • A write request must wait until previously written data has been written to the media.

  • A device must be opened, such as a modem terminal line waiting for a carrier or a FIFO waiting for a reader.

  • Mandatory locking is enabled on files, causing a wait for locking on a read or a write system call.

Conceptually, the simplest solution to this problem is to not put the process to sleep. When the I/O cannot be completed, the system call returns an error indicating that it cannot succeed at this time. This is non-blocking I/O.

Opening Files in Non-Blocking Mode

One method of specifying to the UNIX kernel ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.