title: write socket causes "program exited with code 141" in C
body: <p>I'm trying to setup a client/server in C. I establish the connection, then I want to send an username and a pwd to the server, and the server has to reply confirming that he has received the usr/pwd. The problem is that both server and client exit as soon as they meet the "write" or "read" function. What should I do?</p>
  
  <p>server.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;signal.h&gt;
  
  void main(){
     int ds_sock;
     struct sockaddr_in my_addr;
     ds_sock=socket(AF_INET,SOCK_STREAM,0);
  
     memset(&amp;my_addr,0,sizeof(my_addr));
     my_addr.sin_family=AF_INET;
     my_addr.sin_port=htons(25000);
     my_addr.sin_addr.s_addr=INADDR_ANY;
  
     if(bind(ds_sock,(struct sockaddr *)&amp;my_addr,sizeof(my_addr))&lt;0){
         printf("error in bind");
     }
  
     listen(ds_sock,2);
     int ds_sock_acc;
     struct sockaddr_in addr;
     size_t sin_size = sizeof(struct sockaddr_in);
     signal(SIGCHLD,SIG_IGN);
     while(1){
         if((ds_sock_acc=accept(ds_sock,(struct sockaddr *)&amp;addr,&amp;sin_size))&lt;1){
             printf("error accept");
         }
      printf("connected");
      char usr[10];
      read(ds_sock,usr,10);
      char* confirm_usr;
      confirm_usr="Username received";
      write(ds_sock,confirm_usr,100);
  
      char pwd[10];
      read(ds_sock,pwd,10);
      char* confirm_pwd;
      confirm_pwd="Password received";
      write(ds_sock,confirm_pwd,100);
     }    
  }
  </code></pre>
  
  <p>client.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netdb.h&gt;
  
  void main(){
      int ds_sock;
      ds_sock = socket(AF_INET, SOCK_STREAM,0);
  
      int ret;
      struct sockaddr_in Eaddr;
      Eaddr.sin_family = AF_INET;
      Eaddr.sin_port = htons(25000);
      Eaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
      ret = connect(ds_sock,(struct sockaddr *)&amp;Eaddr,sizeof(Eaddr));
      if(ret==-1){ 
          printf("error connect");
          exit(EXIT_FAILURE);
      }
      printf("connect OK");
  
      char usr[10];
      printf("Insert username");
      scanf("%s",usr);
  
      char pwd[12];
      printf("Insert password");
      scanf("%s",pwd);
      printf("%s",pwd);
  
      write(ds_sock,usr,10);  
      char usr_reply[100];
      read(ds_sock,usr_reply,100);
      printf("%s",usr_reply);
  
      write(ds_sock,pwd,12);
      char pwd_reply[100];
      read(ds_sock,pwd_reply,100);
      printf("%s",pwd_reply);
  }
  </code></pre>