On Thu, Jul 29, 2021 at 06:52:37AM -0400, Polyna-Maude Racicot-Summerside wrote: > As far as I know, sync doesn't work in the background !
On many systems, it does. I can't even find a clear statement in the bullseye sync(1) man page of whether it does or not. The bullseye sync(1) comes from GNU coreutils 8.32. Googling turns up a different sync(8) page, <https://linux.die.net/man/8/sync> which says: On Linux, sync is only guaranteed to schedule the dirty blocks for writing; it can actually take a short time before all the blocks are finally written. The reboot(8) and halt(8) commands take this into account by sleeping for a few seconds after calling sync(2). That man page claims to be from fileutils-4.0. On bullseye, sync(2) says: According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done. However Linux waits for I/O completions, and thus sync() or syncfs() provide the same guarantees as fsync() called on every file in the sys‐ tem or filesystem respectively. So, even on Linux systems, it would appear the behavior has varied over time. On non-Linux systems, I would expect a high probability that the sync(8) or sync(1) command returns immediately, without waiting for the synchronization to complete.