title: C pipe not functioning with large writes
body: <p>Wrote a little script to work with <code>php5-cgi</code> using <code>fork()</code>,<code>exec()</code> and pipes. Script below works well when output of <code>php5-cgi</code> is small. But when it's considerably large (when using <code>&lt;?php phpinfo(); ?&gt;</code> in the input file), it does not return anything.</p>
  
  <pre><code>#include&lt;netinet/in.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;sys/socket.h&gt;
  #include&lt;sys/stat.h&gt;
  #include&lt;sys/types.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;fcntl.h&gt;
  
  int main(int argc, char const *argv[]) {
  
    int status;
    int link[2];
    char out[4096];
    char * arg[3]={"php5-cgi","a.php",0};
    if (pipe(link)==-1){
      perror("pipe");
    }
    int pid=fork();
    if (!pid){
      dup2 (link[1], 1);
      close(link[0]);
      execvp("php5-cgi", arg);
    } else {
      waitpid(pid, &amp;status,0);
      close(link[1]); // parent doesn't write
          char reading_buf[1];
          while(read(link[0], reading_buf, 1) &gt; 0){
              write(1, reading_buf, 1);
          }
          close(link[0]);
    }
    printf("%s\n", "end");
    return 0;
  }
  </code></pre>
  
  <p>I assume this is due to overflow of pipe. I there any way to fix this issue? Or is there any alternatives to deal with large ouput?</p>