title: Two way pipe communication between parent and child
body: <p>I'm trying to create two-way communication between parent and child processes using 2 pipes in C.the prog1 running in child1 
  I want to read 3+4+5 from prog1 after that send something to prog1 with write but I could not.
  Where is the wrong?</p>
  
  <pre><code>/* prog1.c */
  
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  void
  main(void){
      int FD;
  unsigned int buf;
  char buf[15];
  
  printf("7+5+11=?\n");
  FD=read(0,buf,10);
  if(FD&lt;0){
      perror("FAIL\n");
  exit(EXIT_FAILURE);
  }
       printf("TAKED:%s\n",buf);
  }
  </code></pre>
  
  <p>prog2.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/wait.h&gt;
  void ERR_SYS(const char *msg);
  int
  main(void){
      char buf[15];
      int pipe1[2];
      int pipe2[2];
      pid_t childpid;
  
      memset(buf,'\0',14);
  
      if(pipe(pipe1) &lt; 0 || pipe(pipe2) &lt; 0)
       ERR_SYS("fail_pipe");
  
      if((childpid = fork()) &lt; 0)
       ERR_SYS("fail_fork");
  
      if(childpid==0)
      {
        dup2(pipe2[1],1);
            dup2(pipe1[0],0);
        close(pipe1[1]);
            close(pipe2[0]);
        close(pipe2[1]);
        close(pipe1[0]);
            //close(1);
            //close(0);
        execle("./prog1",NULL,NULL,NULL);
      }else{
  
       close(pipe1[0]);
       close(pipe2[1]);
       read(pipe2[0],buf,4); /*I hope to read 3+4+5*/
       printf("BuF::%s\n",buf);
       write(pipe1[1],"off",3);/*send {off}*/
       wait(NULL);
      }
   return 0;
   }
  
   void 
   ERR_SYS(const char *msg)
   {
       perror(msg);
       exit(EXIT_FAILURE);
   }
  </code></pre>