title: C: "write: Broken pipe" error
body: <p>I want to try Pipe communication with child and parent process. Parent process write to pipe and child process read this but my program get error "write: Broken pipe". How can I change this code?
  Thnks.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;termios.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;fcntl.h&gt;
  
  
  int main(void)
  {
      int i=0;
      int child=5;
      int fdp;
      int fds[2];
      int controlRead;
      int controlWrite;
      char pathName[30] = {"Trying Pipe Communication\n"};
  
  
      if(pipe(fds) &lt; 0)
      {
          perror("pipe");
          exit(EXIT_FAILURE);
      }
  
      do{
  
          if(child == 0)
          {
              close(fds[1]);
              if( (controlRead = read(fds[0],pathName,sizeof(pathName)) ) &lt;= 0)
              {
                  perror("read");
                  exit(EXIT_FAILURE);
              }
              close(fds[0]);
  
              printf("boru :%s\n",pathName);
              wait();
          }
          else
          {
  
              printf("Parent process\n");
              close(fds[0]);
              if( (controlWrite = write(fds[1],&amp;pathName,sizeof(pathName))) &lt;= 0)
              {
                  perror("write");
                  exit(EXIT_FAILURE);
              }
              close(fds[1]);
  
  
          }
          i++;
          child = fork();
      }while(i&lt;3);
  
      return 0;
  }
  </code></pre>