title: Why does this C program generate SIGPIPE later than expected?
body: <p>This program generates <code>SIGPIPE</code> after piping it to "<code>head -n 1</code>", after a random time. I understand that because we're feeding more to "<code>head -n 1</code>" after the first line, we would expect it to generate <code>SIGPIPE</code>, but instead it will make it to a random number (usually > 20 and &lt; 200) before exitting. Any idea why?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  main()
  {
    int i;
    char *s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
  
    i = 0;
    while (1) {
      fputs(s, stdout);
      fflush(stdout);
      fprintf(stderr, "Iteration %d done\n", i);
      i++;
    }
  }
  </code></pre>
  
  <p>This is not homework, just something in my professor's notes that I do not understand.</p>