Sync (Unix)

From Wikipedia, the free encyclopedia

The correct title of this article is sync. The initial letter is shown capitalized due to technical restrictions.

sync is a standard system call in the Unix operating system, which commits to disk all data in the kernel filesystem buffers, i.e. data which has been scheduled for writing via low-level I/O system calls. Note that higher-level I/O layers such as stdio may maintain separate buffers of their own.

As a function in C, the sync() call is typically declared as void sync(void) in <unistd.h>. The system call is also available via a command line utility also called sync, and similarly named functions in other languages such as Perl.

The related system call fsync commits just the buffered data relating to a specified file descriptor.

Unix systems typically run some kind of flush or update daemon, which calls the sync function on a regular basis. Buffers are also flushed when filesystems are unmounted or remounted read-only, for example prior to system shutdown.