How can I tell when the other end of a connection shuts down?

How can I tell when the other end of a connection shuts down?


If you try to read from a pipe, socket, FIFO etc. when the writing end
of the connection has been closed, you get an end-of-file indication
(read() returns 0 bytes read). If you try and write to a pipe,
socket etc. when the reading end has closed, then a SIGPIPE
signal will be delivered to the process, killing it unless the signal is
caught. (If you ignore or block the signal, the write() call
fails with EPIPE.)






Home FAQ