Program received signal SIGPIPE, Broken pipe

后端 未结 5 1942
陌清茗
陌清茗 2020-12-04 14:50

I write a client program based on posix sockets. The program creates multiple threads and is going to lock the server. But during debug in gdb time the program gives an info

相关标签:
5条回答
  • 2020-12-04 14:55

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

    0 讨论(0)
  • 2020-12-04 14:59

    I sort of experienced the same problem and it let me to this SO post. I got sporadic SIGPIPE signals causing crashes of my fastcgi C program run by nginx. I tried to signal(SIGPIPE, SIG_IGN); without luck, it kept crashing.

    The reason was that nginx's temp dir had a permission problem. Fixing the permissions solved the SIGPIPE problem. Details here on how to fix and more here.

    0 讨论(0)
  • 2020-12-04 15:10

    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.

    0 讨论(0)
  • 2020-12-04 15:14

    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);
    
    0 讨论(0)
  • 2020-12-04 15:15

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

    (gdb) handle SIGPIPE nostop

    0 讨论(0)
提交回复
热议问题