title: C Programming 2 pipes
body: <p>I want to set up 2 pipes in my program. I have 1 pipe working fine, but I don't know where to place the second pipe. </p>
  
  <p>The pseudo code of my setup is shown below,</p>
  
  <p>Here is it with curly braces sorry about that</p>
  
  <pre><code>//the first pipe:   
  pipe(pipe1) 
  
  //the second pipe:  
  pipe(pipe2) 
  
  pid = fork()
  
  if(pid == 0) {
  
    dup2(pipe1[1], 1)
    close(pipe1[0])
    execvp(beforepipe)
    }  
  
  if(pid &gt; 0) { //everything below is in here
  
    pid2 = fork()
  
    if(pid2 == 0){
  
      //pipe1
      dup2(pipe1[0],0)
      dup2(out,1)
      close(pipe1[1])
      execvp(afterpipe)
  
      //pipe2 does not work might need to be placed in different area
      dup2(pipe1[1],1)
      close(pipe1[0])
      execvp(beforepipe1)
      }
  
    if(pid2 &gt; 0){
      close(pipe[0])
      close(pipe[1])
      wait() //this is an infinite for loop
  
      pid3 = fork()
  
      if(pid3 == 0){
        dup2(pipe2[0],0)
        dup2(out,1)
        close(pipe2[1])
        execvp(afterpipe2)
        }
  
      if(pid3 &gt; 0) {
        close(pipe2[0])
        close(pipe2[1])
        wait()
        }
      }
  </code></pre>
  
  <p>The position of the second pipe is in the wrong place or the code is altogether wrong.</p>
  
  <p>Any suggestions? </p>