fsync() - synchronize disk and in-memory versions of a file
#include <unistd.h>
int fsync (int fd)
The fsync(2) call flushes the buffer for the specified file descriptor causes all modified data and attributes of fd to be moved to a permanent storage device. It flushes to disk the buffers for the specified file descriptor.
Use fsync(2) in programs that require a file to be in a known state, for example, in building a simple transaction facility.
The fsync(2) call returns 0 for success. On an error, it returns -1 and sets errno to indicate the error.
The fsync(2) call fails for the following reasons: