当前位置: 技术问答>linux和unix
请教:linux下的有名管道 fifo深度多大?
来源: 互联网 发布时间:2016-07-16
本文导语: 从网上和学习资料中看,fifo的最大深度应该是PIPE_BUF这个值,查了一下是4096,但是我在网fifo里一直写(不读取出来),然后同时读取当前的fifo中的数据字节数(ioctl(fd, FIONREAD, &read_len)),发现可以大于这个4096...
从网上和学习资料中看,fifo的最大深度应该是PIPE_BUF这个值,查了一下是4096,但是我在网fifo里一直写(不读取出来),然后同时读取当前的fifo中的数据字节数(ioctl(fd, FIONREAD, &read_len)),发现可以大于这个4096啊?怎么回事?
|
[test@test ~]$ man 7 pipe
Pipe Capacity
A pipe has a limited capacity. If the pipe is full, then a write(2)
will block or fail, depending on whether the O_NONBLOCK flag is set
(see below). Different implementations have different limits for the
pipe capacity. Applications should not rely on a particular capacity:
an application should be designed so that a reading process consumes
data as soon as it is available, so that a writing process does not
remain blocked.
In Linux versions before 2.6.11, the capacity of a pipe was the same as
the system page size (e.g., 4096 bytes on i386). Since Linux 2.6.11,
the pipe capacity is 65536 bytes.
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 non-atomic: 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 non-blocking (O_NONBLOCK), whether there are multi-
ple writers to the pipe, and on n, the number of bytes to be written:
...............................
Pipe Capacity
A pipe has a limited capacity. If the pipe is full, then a write(2)
will block or fail, depending on whether the O_NONBLOCK flag is set
(see below). Different implementations have different limits for the
pipe capacity. Applications should not rely on a particular capacity:
an application should be designed so that a reading process consumes
data as soon as it is available, so that a writing process does not
remain blocked.
In Linux versions before 2.6.11, the capacity of a pipe was the same as
the system page size (e.g., 4096 bytes on i386). Since Linux 2.6.11,
the pipe capacity is 65536 bytes.
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 non-atomic: 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 non-blocking (O_NONBLOCK), whether there are multi-
ple writers to the pipe, and on n, the number of bytes to be written:
...............................
|
那就是大于4096呗!