title: no result!! using fork() to run execlp() with 2 pipes using dup2
body: <p>I am writing a C program which will run Linux commands, like: <br/>
  <code>cat /etc/passwd | grep list | cut -c 1-5</code><br/>
  and i didnt have any result<br/>
  *here the parent wait for the first child(child_pid) to finish;<br/>and the first child wait for the second(pfils) !!<br/>
  any idea?<br/>
  code :<br/></p>
  
  <pre><code>main()
  {
      pid_t child_pid;
      int fd[2];
      int pfd[2];
      pipe(pfd);
      child_pid = fork ();
  
      if (child_pid != 0) 
      {
          wait(child_pid);
          close(pfd[1]);
          dup2(pfd[0],0);
          close(pfd[0]);
          execlp("cut","cut","-c","1-5",NULL);
      }
      else
      {
          pid_t pfils = fork();
          pipe(fd);
  
          if(pfils == 0)
          {
              close(fd[0]);
              dup2(fd[1],1);
              close(fd[1]);
              execlp("cat", "cat","/etc/passwd",NULL);
          }
          else
          {
              wait(pfils);
              close(fd[1]);
              dup2(fd[0],0);
              close(fd[0]);
              close(pfd[0]);
              dup2(pfd[1],1);
              close(pfd[1]);
              execlp("grep","grep","list",NULL);
          }
      }
  }
  </code></pre>