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 specific
  • syncer(4) β€” the kernel process doing the 30-second check-ins, she never misses
  • sync(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