7

For example, I have a script that writes the time to a pipe in /etc/pipe. It writes continuously in a while true loop. How long will the data in the pipe be available for reading? If I only decide to read the pipe a day later with cat /etc/pipe, will I get all the time values right from the time I started writing?

Conversely, what if my loop only wrote the time every 10 minutes. Will I be able to access everything a day later?

Finally, pretend my loop writes the time continuously (like my first example) and I read the pipe every 30 minutes. If my computer shuts down right before I read the pipe, will the pipe be empty when I reboot or will it hold all that data?

1 Answer 1

7

The process will be able to write PIPE_BUF bytes (see linux/limits.h) into the pipe. Then it will be stuck, until some of the data will be read.

The buffered data will be kept around as long as at least one end of the pipe is open – there is no "timeout" or anything like that. Buffers are kept in memory, however, and will not persist reboots.

See the pipe(7) manual page, especially the "Pipe Capacity" section, for more information.

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).

[...] Since Linux 2.6.11, the pipe capacity is 65536 bytes.

4
  • 1
    Can this value be changed safely?
    – nopcorn
    Commented Aug 2, 2011 at 15:48
  • @MaxMackie It should be a constant. Commented Aug 2, 2011 at 15:55
  • I got that, I meant is there a special way to change it without having other issues with other programs. And is it dangerous to set the value to a very high constant?
    – nopcorn
    Commented Aug 2, 2011 at 15:59
  • 1
    @MaxMackie I guess you could compile a special version of kernel from modified sources. Commented Aug 2, 2011 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .