fsync
also: fsync(), file synchronization
A system call that forces the kernel to write all pending file data and metadata to disk immediately, ensuring data persistence even if the system crashes.
fsync() is a system call that synchronizes a file's in-memory data with the persistent storage device. When you write to a file, the kernel typically buffers the data in RAM for performance reasons. fsync() bypasses this buffering and forces an immediate write to disk.
This is critical for applications that cannot tolerate data loss, such as databases, transaction logs, or mail servers. Without fsync(), a power failure or system crash could result in recently written data being lost.
Example: A database might call fsync() after committing a transaction to guarantee the changes are safely written to disk before confirming to the user.
Note that fsync() can be expensive in performance terms since disk writes are much slower than RAM operations. Related calls include fdatasync() (syncs only data, not metadata) and sync() (syncs all filesystems).