当前位置: 技术问答>linux和unix
关于 PIPE
来源: 互联网 发布时间:2017-03-25
本文导语: PIPE 用于父子进程的通信。 有一个疑问,对于往 PIPE 中写入超大数据的场景,系统是如何定义的?在 FIFO 中有 PIPE_BUF 的相关定义,不知道这个定义是否同样适合 PIPE? | Pipe和FIFO一样有PIPE_BUF的定义...
PIPE 用于父子进程的通信。
有一个疑问,对于往 PIPE 中写入超大数据的场景,系统是如何定义的?在 FIFO 中有 PIPE_BUF 的相关定义,不知道这个定义是否同样适合 PIPE?
有一个疑问,对于往 PIPE 中写入超大数据的场景,系统是如何定义的?在 FIFO 中有 PIPE_BUF 的相关定义,不知道这个定义是否同样适合 PIPE?
|
Pipe和FIFO一样有PIPE_BUF的定义,man 7 pipe可见详细说明
PIPE_BUF
POSIX.1-2001 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 nonatomic: the kernel may interleave the data with data written by other processes. POSIX.1-2001
requires PIPE_BUF to be at least 512 bytes. (On Linux, PIPE_BUF is 4096 bytes.) The precise semantics depend on whether the file descriptor is
nonblocking (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
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 written), and these bytes may be
interleaved with writes by other processes.
PIPE_BUF
POSIX.1-2001 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 nonatomic: the kernel may interleave the data with data written by other processes. POSIX.1-2001
requires PIPE_BUF to be at least 512 bytes. (On Linux, PIPE_BUF is 4096 bytes.) The precise semantics depend on whether the file descriptor is
nonblocking (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
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 written), and these bytes may be
interleaved with writes by other processes.
|
默认是阻塞的,
如果要修改,可以用fcntl,也可以用 pipe2(int pipefd[2], int flags)直接把flag设置成O_NONBLOCK
如果要修改,可以用fcntl,也可以用 pipe2(int pipefd[2], int flags)直接把flag设置成O_NONBLOCK
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。