I work on an C++ project in Linux where two programs communicate over a named pipe.
Now I want to detect in one program if the other disconnects from the named pipe.
Is there a way to detect the disconnect?
Edit
I opened the fifo in O_RDWR mode – that was the reason that select didn’t react on the disconnect. Now I open the fifo with (O_RDONLY | O_NDELAY) and all works fine.
This is same as in TCP/IP. You need to attempt to read data, if that fails with 0, pipe is closed.
read and recv:
There is also
SIGPIPEsignal. It’ll be sent when you try write to a broken pipe – pipe with no readers.