title: write and printf out of order output
body: <p>While writing a c program I encountered a puzzling behavior with printf and write. It appears that write is in some cases called before printf even though it is after it in the code (is printf asynchronous?). Also if there are two lines in the printf, output after that appears to be inserted between them. My question is what causes this behavior and how can I know what will happen when? What about other output functions (ex. puts) - can I look out for something in the documentation to know how they will behave with others. Example code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(void)
  {
      write(STDOUT_FILENO, "1.", 2);
      printf("2.");
      write(STDOUT_FILENO, "3.", 2);
      printf("4.\n5.");
      printf("6.");
      write(STDOUT_FILENO, "7.", 2);
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1.3.2.4.
  7.5.6.
  </code></pre>