- 论坛徽章:
- 0
|
- PIPE_BUF
- POSIX.1 says that write(2)s of less than PIPE_BUF bytes must be atomic:
- the output data is written to the pipe as a contiguous sequence.
- Writes of more than PIPE_BUF bytes may be non-atomic: the kernel may
- interleave the data with data written by other processes. POSIX.1
- requires PIPE_BUF to be at least 512 bytes. (On Linux, PIPE_BUF is
- 4096 bytes.) The precise semantics depend on whether the file descrip-
- tor is non-blocking (O_NONBLOCK), whether there are multiple writers to
- the pipe, and on n, the number of bytes to be written:
-
- O_NONBLOCK disabled, n <= PIPE_BUF
- All n bytes are written atomically; write(2) may block if there
- is not room for n bytes to be written immediately
-
- O_NONBLOCK enabled, n <= PIPE_BUF
- If there is room to write n bytes to the pipe, then write(2)
- succeeds immediately, writing all n bytes; otherwise write(2)
- fails, with errno set to EAGAIN.
-
- O_NONBLOCK disabled, n > PIPE_BUF
- The write is non-atomic: the data given to write(2) may be
- interleaved with write(2)s by other process; the write(2) blocks
- until n bytes have been written.
-
- O_NONBLOCK enabled, n > PIPE_BUF
- If the pipe is full, then write(2) fails, with errno set to
- EAGAIN. Otherwise, from 1 to n bytes may be written (i.e., a
- "partial write" may occur; the caller should check the return
- value from write(2) to see how many bytes were actually writ-
- ten), and these bytes may be interleaved with writes by other
- processes.
复制代码 |
|