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.

Leave a Comment