Program received signal SIGPIPE, Broken pipe

The process received a SIGPIPE. The default behaviour for this signal is to end the process.

A SIGPIPE is sent to a process if it tried to write to a socket that had been shutdown for writing or isn't connected (anymore).

To avoid that the program ends in this case, you could either

  • make the process ignore SIGPIPE

    #include <signal.h>
    
    int main(void)
    {
      sigaction(SIGPIPE, &(struct sigaction){SIG_IGN}, NULL);
    
      ...
    

    or

  • install an explicit handler for SIGPIPE (typically doing nothing):

    #include <signal.h>
    
    void sigpipe_handler(int unused)
    {
    }
    
    int main(void)
    {
      sigaction(SIGPIPE, &(struct sigaction){sigpipe_handler}, NULL);
    
      ...
    

In both cases send*()/write() would return -1 and set errno to EPIPE.


You have written to a connection that has already been closed by the peer.


A workaround for SIGPIPE, you can ignore this signal by this code:

#include <signal.h>

/* Catch Signal Handler functio */
void signal_callback_handler(int signum){

        printf("Caught signal SIGPIPE %d\n",signum);
}

in your code (main or globally)

/* Catch Signal Handler SIGPIPE */
signal(SIGPIPE, signal_callback_handler);

When debugging with 'gdb', it is possible to manually disable SIGPIPE as follows:

(gdb) handle SIGPIPE nostop