# Linux – How long do FIFOs (named pipes) stay “open” for

fifolinuxnamed-pipepipeunix

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?

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