Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
Can this value be changed safely? –  MaxMackie Aug 2 '11 at 15:48
    
@MaxMackie It should be a constant. –  Let_Me_Be Aug 2 '11 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? –  MaxMackie Aug 2 '11 at 15:59
1  
@MaxMackie I guess you could compile a special version of kernel from modified sources. –  Let_Me_Be Aug 2 '11 at 16:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.