title: Creating three children and connecting pipes between them
body: <p>I am in need of some help of understanding how to create one parent and three children and connecting pipes between the childrens. </p>
  
  <p>My task is to get the first child to run <code>ls -l /bin/??</code> and send it to the second child that will run <code>grep rwxr-xr-x</code> and send that to the third child that will run <code>sort</code>.</p>
  
  <p>It wil look like this if typed in to bash:<br>
  <code>ls -l /bin/?? | grep rwxr-xr-x | sort</code></p>
  
  <p>My code right now:</p>
  
  <pre><code>#include &lt;sys/wait.h&gt;
  #include &lt;sys/types.h&gt;
  #inlcude &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  #define READ 0
  #define WRITE 1
  
  int main()
  {
    int fds[2], i;
    pid_t pid;
    pipe(fds);
  
    for(i = 0; i &lt; 3; i++)
    {
       pid = fork();
       if(pid == (pid_t) 0)
          if(i == 0)
          {
             /* First child */
          }
       else if(i == 1)
       {
          /* second child */
       }
       else if(i == 2)
       {
          /* Third child */
       }
       break;
    else 
    {
        /* This is the parent */
    }
   }
  }
  </code></pre>
  
  <p>The problem is that i don't really know if this is the correct way of doing it. 
  Please avoid telling me to do this with threads as I am trying to learn pipes and communication between processes.</p>