title: Difference between buffered io and unbuffered io
body: <p>i have a question about buffer in I/O programming in C.<br>
  For example, it is always said that <em>fwrite</em> is a buffered i/o, and <em>write</em> is an unbuffered i/o. My understanding is that the 'buffered' here is in application layer, and i think in kernel level, they both have a buffer. From APUE, i saw:  </p>
  
  <blockquote>
    <p>Traditional implementations of the UNIX System havea buffer cache or
    page cache in the kernel throughwhich  most disk I/O passes. When we
    write data to a file,the data is normally copied by the kernel into
    oneof its  buffers and queued for writing to disk at some later time.
    This is called delayed write.</p>
  </blockquote>
  
  <p>Am i right? So i do a experiment:  </p>
  
  <pre><code> int main() {
      char *fname = "helloworld";
      char content[] = "abcdefg";
      int fd = open(fname, O_WRONLY | O_CREAT);
      int flag = fcntl(fd, F_GETFL);
      flag &amp;= ~O_SYNC;
      fcntl(fd, F_SETFL, flag);
      write(fd, content, 3);
      sleep(100);
      return 0;
     }
  </code></pre>
  
  <p>I thought there should be nothing outputed during sleep, but the fact is the opposite.<br>
  Is there something i misunderstood?</p>