3 ms·
I've definitely seen `sync` itself waiting/blocking (especially if you use fuse for something network based and disconnect the cable first), but whether it's gu
by viraptor 13y ago
I've definitely seen `sync` itself waiting/blocking (especially if you use fuse for something network based and disconnect the cable first), but whether it's guaranteed or not... that's an interesting question.
Edit: after some googling:
On Linux, sync is guaranteed only 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).
This page describes sync as found in the fileutils-4.0 package; other
versions may differ slightly.
So it doesn't look like the writes are guaranteed to take place. Just a best effort + wait + pray :)
- deleted 13y ago[deleted]
- jabiko 13y agoInteresting. http://linux.die.net/man/2/sync http://linux.die.net/man/2/sync says On Linux, sync is guaranteed only to schedule the dirty blocks for According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done. However, since version 1.3.20 Linux does actually wait. (This still does not guarantee data integrity: modern disks have large caches.) So it seems like the sleep(2) is there to give the disk enough time to write the cache data.
- igravious 13y agoPity no-one thought to comment this little piece of reboot/halt magic - 'twould have saved a bit of digging.
- JoeAltmaier 13y agoI changed an OS (before Linux) to sync when idle. So by the time you could type a shutdown command, it was already sync'd. I don't know why more OSs don't do that.