Say an application opens for writing, a file, which is a FIFO to which something is “listening”, and later, this “listener” closes; if the application attempts to write to it, the application will get a broken pipe error. That's OK, but I wonder if there is a risk for the handle to be reused and therefore a risk for writing to an handle which is not anymore what's supposed to be. Thus the question: what's the persistence of the handle of a broken FIFO? How long can an application rely on the broken pipe error, to know the other end of the FIFO was closed? Or is it guaranteed the handle will never be reused for all the lifetime of the application unless it has explicitly closed it?
Asked
Active
Viewed 852 times
1 Answers
2
A file descriptor will continue to be associated with the file or FIFO that was used in the open call until it's closed (by calling close
or dup2
, or the process exiting, etc.) Even if the file or FIFO corresponding to an open file descriptor is deleted (as in this question) and another file with the same name created, you'll still be able to do I/O to the original file as long as the file descriptor remains open. Also, there is no timeout that will cause a FIFO to be shut down due to inactivity.

Mark Plotnick
- 25,413
- 3
- 64
- 82
fd
. Ex. if the application waits long enough, is this possible the handle is reused for another FIFO or file, or is the handle not reused unless it was closed by the application too? Anyway, thanks for your other point, which is worth reading. – Hibou57 Feb 28 '15 at 01:01