-1

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?

Hibou57
  • 905
  • 1
    Not sure what handle means in this context. Are you asking whether another reader can open the same FIFO after the first reader closes it without the writer being able to detect this? – Mark Plotnick Feb 28 '15 at 01:00
  • @Mark Plotnick: I was rather asking about what can happen of the 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
  • To the one who down‑voted: wouldn't it be useful to at least tell why? Is the question off‑topic? Unintelligible? (I don't think so for the latter, as someone was able to answer it) – Hibou57 Feb 28 '15 at 02:49

1 Answers1

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