1. Source
Fflush is the method provided in libc.,
Fsync is a system call provided by the system.
2. Prototype
Fflush accepts a parameter file *.
Fflush (File *);
Fsync accepts an int-type file descriptor.
Fsync (int fd );
3. Functions
Fflush: writes the buffer calling write function in the C library to the disk [actually writing the buffer to the kernel].
Fsync: fl the kernel buffer to the disk.
C Library Buffer ----- fflush ---------> kernel buffer -------- fsync -----> Disk
For more information about Kernel buffering, standard library buffering, and user space buffering, see apue 5.14:
One inefficiency inherent in the standard I/O Library is the amount of data copying that takes place. When we use the line-at-a-time functions,FgetsAndFputs, The data is usually copied twice: once between the kernel and the standard I/O buffer (when the correspondingReadOrWriteIs issued) and again between the standard I/O buffer and our line buffer.