SYNC(2)
π SYNC(2) π
ok bestie so this is sync, from the System Calls Manual β the actual syscall, not the little sync(8) command, they're different girlies, don't get it twisted π«Ά
β¨ NAME β¨
sync β schedule file system updates πΎβ¨
π LIBRARY π
Standard C Library (libc, -lc) β she lives in libc, that's her home π
πΈ SYNOPSIS πΈ
#include <unistd.h>
void
sync(void);
like. that's it. no args. no return value. no drama. she just does it π
π¦ DESCRIPTION π¦
okay so here's the tea π΅ β the sync() system call forces a write of dirty (modified) buffers in the block buffer cache out to disk. "Dirty" here means modified, not like, unwashed. The kernel be holding onto this info in core (i.e. in memory) to cut down on the number of disk I/O transfers the system needs β which is smart, because disk is slow and memory is fast, iykyk.
BUT. π¨ And this is the important part. Because all that cached info is lost after a system crash, the kernel process syncer(4) issues a sync() system call frequently β like, about every 30 seconds β so your data doesn't just evaporate the second something goes sideways. She's the responsible one. The main character who sets an alarm. π
If you wanna sync one specific file's business instead of the whole entire system, that's a different girl: the fsync(2) system call may be used to synchronize individual file descriptor attributes β¨
π SEE ALSO π
fsync(2)β the single-file-descendant version, for when you're being specificsyncer(4)β the kernel process doing the 30-second check-ins, she never missessync(8)β the command-line one, NOT the syscall, ok bestie, they're cousins π§
π HISTORY π
The sync() function appeared in Version 3 AT&T UNIX. ancient. iconic. still here. we love a legacy queen π
π BUGS π
the sync() system call may return before the buffers are completely flushed.
like... she said she's done but she's not done done π it's giving "on my way!" while still in bed. So don't treat a return from sync() as a guarantee that everything hit the disk, because fr fr it isn't one. π
so yeah that's the whole page bestie, that was SYNC(2) from the System Calls Manual, brought to you by Debian, dated December 1, 2017 β go forth and flush those buffers responsibly ππβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms