《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 

 

 

 

转载于:https://www.cnblogs.com/tianji/archive/2012/05/14/2499452.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值