As long as at least one process keeps the pipe open, the object will not be deleted.
That is, even if the FIFO file is deleted (according to stat() ), read() can still return data from an already open pipe.
If there are no processes in which pipe is open for writing, then read() will return 0 (to mark EOF) if there is no more data in the pipe buffer.
If your task is to read data from a FIFO, then open ( open() ) and read ( read() ), remembering to handle errors. No additional calls needed.
Here is an example that shows that data can be written and read even if stat() says that there is no file (executable pseudo-code):
#!/usr/bin/env python from os import * mkfifo('fifo') # create named pipe r, w = pipe() # "communication tube" between the parent and the child if fork(): # parent process (the reader) close(r) # close the unused end of the pipe fd = open('fifo', O_RDONLY) # open for reading write(1, read(fd, 512)) # read some remove('fifo') # delete fifo write(w, b'\0') # tell the child, the parent removed fifo close(w) # nothing more to say wait() # wait until the writer exits write(2, b'read some more\n') write(1, read(fd, 512)) # read some more if not read(fd, 512): write(1, b'EOF') # read() returns nothing else: # child: writer process close(w) # close the unused end of the pipe fd = open('fifo', O_WRONLY) # open for writing write(fd, b'data\n') read(r, 512) # wait until the parent removes fifo close(r) # won't listen no more try: # make sure fifo is gone stat('fifo') except IOError: pass else: assert 0, "shouldn't happen" write(fd, b'more data\n') # write after fifo is removed _exit(0)
If you are interested in finding out when the file name (fifo) was removed (and not the ability to read data), then to stat() not to be called continuously, you can use services such as the suggested @avp inotify for Linux to use (on different systems — different interfaces, but opportunity on many common systems is).
selectwith timeout and callstatto check if the FIFO is deleted (do you write in linux? There is usually a so-called named channel) - avp