Chinaunix首页 | 论坛 | 博客
  • 博客访问: 442627
  • 博文数量: 70
  • 博客积分: 3170
  • 博客等级: 中校
  • 技术积分: 756
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-06 16:47
文章分类

全部博文(70)

文章存档

2011年(22)

2010年(33)

2009年(5)

2008年(10)

分类: C/C++

2011-01-17 12:42:36

  1. PIPE_BUF
  2.        POSIX.1 says that write(2)s of less than PIPE_BUF bytes must be atomic:
  3.        the  output  data  is  written  to  the  pipe as a contiguous sequence.
  4.        Writes of more than PIPE_BUF bytes may be non-atomic:  the  kernel  may
  5.        interleave  the  data  with  data  written by other processes.  POSIX.1
  6.        requires PIPE_BUF to be at least 512 bytes.   (On  Linux,  PIPE_BUF  is
  7.        4096 bytes.)  The precise semantics depend on whether the file descrip-
  8.        tor is non-blocking (O_NONBLOCK), whether there are multiple writers to
  9.        the pipe, and on n, the number of bytes to be written:

  10.        O_NONBLOCK disabled, n <= PIPE_BUF
  11.               All  n bytes are written atomically; write(2) may block if there
  12.               is not room for n bytes to be written immediately

  13.        O_NONBLOCK enabled, n <= PIPE_BUF
  14.               If there is room to write n bytes to  the  pipe,  then  write(2)
  15.               succeeds  immediately,  writing  all n bytes; otherwise write(2)
  16.               fails, with errno set to EAGAIN.

  17.        O_NONBLOCK disabled, n > PIPE_BUF
  18.               The write is non-atomic: the  data  given  to  write(2)  may  be
  19.               interleaved with write(2)s by other process; the write(2) blocks
  20.               until n bytes have been written.

  21.        O_NONBLOCK enabled, n > PIPE_BUF
  22.               If the pipe is full, then write(2)  fails,  with  errno  set  to
  23.               EAGAIN.   Otherwise,  from  1 to n bytes may be written (i.e., a
  24.               "partial write" may occur; the caller should  check  the  return
  25.               value  from  write(2)  to see how many bytes were actually writ-
  26.               ten), and these bytes may be interleaved with  writes  by  other
  27.               processes.
阅读(1278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~