Reputation: 19452
I checked man 2 sync
It shows sync
and syncfs
void sync(void);
void syncfs(int fd);
syncfs
is easy to understand. An fd is given and the data of that fd is written completely to underlying file systems.
What is it with sync
?
sync() causes all buffered modifications to file metadata and data to be written to the underlying file systems.
Is it that all the buffers in the system are written to fs? or is it that all the files that are opened by this process are written to fs? I didnot quite understand "buffered modifications to file metadata"
Upvotes: 3
Views: 3186
Reputation: 22542
Whenever you issue a write
, send
, write to file-backed mappings or similar things the kernel is not forced to flush that data straight to persistent storage, the underlying network stack, etc... This buffering is done for performance reasons.
sync
instructs the kernel to do exactly this. Empty all buffers.
Upvotes: 3