title: Implementation of ls | wc -l
body: <p>The following code implements:</p>
  
  <pre><code>ls | wc -l
  </code></pre>
  
  <p><strong>code</strong></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>in <code>execlp("ls", "ls", NULL);</code>why we are replacing ls by ls? what this line is trying to implement?   </p>