sync (Unix)

From Wikipedia, the free encyclopedia


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. On some systems, the cron daemon does this. Buffers are also flushed when filesystems are unmounted or remounted read-only, for example prior to system shutdown.