《unix环境高级编程》之 第十四章 高级IO

1、低速系统调用 :可能会使进程永远“阻塞”的一类系统调用。包括:

the system calls are divided into two categories: the "slow" ones and all the others.

The slow system calls are those that can block forever.They include

  • Reads that can block the caller forever if data isn't present with certain file types (pipes, terminal devices, and network devices)

  • Writes that can block the caller forever if the data can't be accepted immediately by these same file types (no room in the pipe, network flow control, etc.)

  • Opens that block until some condition occurs on certain file types (such as an open of a terminal device that waits until an attached modem answers the phone, or an open of a FIFO for writing-only when no other process has the FIFO open for reading)

  • Reads and writes of files that have mandatory(强制性) record locking enabled

  • certain ioctl operations
  • Some of the interprocess communication functions   

     

2、We also said that system calls related to disk I/O are not considered slow, even though the read or write of a disk file can block the caller temporarily.

 

3、非阻塞IO

Nonblocking I/O lets us issue an I/O operation, such as an open, read, or write, and not have it block forever. If the operation cannot be completed, the call returns immediately with an error noting that the operation would have blocked.

 

4、两种方式指定描述符为非阻塞IO

There are two ways to specify nonblocking I/O for a given descriptor.

  1. If we call open to get the descriptor, we can specify the O_NONBLOCK flag 

  2. For a descriptor that is already open, we call fcntl to turn on the O_NONBLOCK file status flag 

 

 

 

posted @ 2012-05-14 15:39  王耀it  阅读(241)  评论(0编辑  收藏  举报