SIGPIPE signal is sent by kernel to programs whose remote end closes or shuts down the socket and your program still tries to send/write operations on closed connection. The default signal handler terminates your program at this situation because of default behavior.

Solution 1:

Ignore the signal using ‘signal(SIGPIPE, SIG_IGN)’

then catch the EPIPE error which will return from the send/write operation due to a broken pipe.

Solution 2:

Pass MSG_NOSIGNAL flag to send(). This is results as same as solution 1