title: Can you please explain what is happening with fflush() and redirected output here?
body: <p>So I wrote a test program and here is the code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {
      int i;
      printf("%s", "entering\n");
      fflush(stdout);
      for (i = 0 ; i &lt; 3 ; i++)
      {
          fork();
          fflush(stdout);
      }
  
      printf("%s", "exiting\n");
  }
  </code></pre>
  
  <p>When I compile and run it in the terminal it displays what I expect it to: "entering" once, and "exiting" some times.  When I run it and redirect the output to a file it displays entering for every exiting. </p>
  
  <p>1) Why does it not output the same thing to terminal and to a file every time?</p>
  
  <p><strong>2) Why does it display entering in the file  8 times but not entering in in the terminal only once (once is what I would expect it to do).</strong></p>
  
  <p>3) Do the fflush() statements make a difference when my output goes to a file?</p>