I use a FIFO (named pipe) for IPC. Now process A calls
mkfifo(path)
open(path)
Naturally open()
will block until the file is written to by process B. Now I need a way to invalidate a FIFO. Therefore I call
unlink(path)
Now I expected that any blocking open
call would return, but they don't and my process hangs indefinitely.
How can I unblock the open
call when the FIFO is unlinked?
Do I have to resort to O_NONBLOCK
?
PS: I tried the suggested write/unlink/close approach to no avail. The open
call blocks immediately.
void invalidate() {
int fd = open(path, O_WRONLY)
unlink(path)
close(fd)
}
I think the issue is
The FIFO must be opened on both ends (reading and writing) before data can be passed. Normally, opening the FIFO blocks until the other end is opened also.
However invalidate
should work without knowing if the FIFO is currently opened for reading or not.