title: The issue when using popen and pclose
body: <p>I have a program which uses <code>popen</code> and <code>pclose</code>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/wait.h&gt;
  int main(void)
  {
      FILE *fp = NULL;
      int ret_val = 0;
  
      fp = popen("ls *", "r");
      if (NULL == fp)
      {
          printf("popen error\n");
          return 1;
      }
  
      ret_val = pclose(fp);
      if (-1 == ret_val)
      {
          printf("pclose error\n");
          return 1;
      }
      else
      {
          printf("%d,%d,%d\n",ret_val, WIFEXITED(ret_val), WEXITSTATUS(ret_val));
      }
      return 0;
  }
  </code></pre>
  
  <p>The output of the program is:  </p>
  
  <pre><code>./test
  Broken Pipe
  36096,1,141
  </code></pre>
  
  <p>My questions are:  </p>
  
  <ol>
  <li>Why is there a "Broken pipe"?</li>
  <li>Why is the exit status code 141? I think "ls *" executed
  successfully and therefore, the exit status should be 0.</li>
  </ol>