fflush

Function Prototype

int fflush(FILE *fp)

Function

  • Any unwritten data in the stream (buffer) are passed to the kernel (buffer cache)
  • All output stream are flushed if fp == NULL

Warning

  • Since fflush pass data to buffer cache and not disk, we might need to call fsync to actually do disk I/O
  • Calling fsync without calling fflush might do nothing if all data are still in the user space buffer instead of kernel space buffer cache