title: forks and pipes implementation linux compiler
body: <p>I have the following code taken from the <a href="http://beej.us/guide/bgipc/output/html/multipage/pipes.html" rel="nofollow">“Pipes” section</a> of <a href="http://beej.us/guide/bgipc/output/html/multipage/index.html" rel="nofollow">Beej’s Guide to Unix IPC</a>.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(void)
  {
      int pfds[2];
  
      pipe(pfds);
  
      if (!fork()) {
          close(1);       /* close normal stdout */
          dup(pfds[1]);   /* make stdout same as pfds[1] */
          close(pfds[0]); /* we don't need this */
          execlp("ls", "ls", NULL);
      } else {
          close(0);       /* close normal stdin */
          dup(pfds[0]);   /* make stdin same as pfds[0] */
          close(pfds[1]); /* we don't need this */
          execlp("wc", "wc", "-l", NULL);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>This code allows the user to see how many files are in a specific directory. How can I edit this code to implement the longer pipeline <code>cat /etc/passwd | cut –f1 –d: | sort</code>? Does anyone have any idea how to do this because I am completely stuck. Any help would be appreciated.</p>