Unix folklore: using multiple sync commands

December 28, 2005

There is persistent bit of folklore in the Unix world that you should do several sync commands before shutting down or rebooting a Unix machine. Even today, you'll see a lot of people following this folklore, generally using 'sync; sync; sync'.

People who do this irritate me, because they are doing it wrong and in a way that makes the whole folklore ineffectual.

The sync folklore dates from the very old days when Unix was primitive and two things were true. First, the sync() system call that the sync program uses just queued dirty buffers to be flushed and didn't guarantee that they had been writing to disk. Second, the kernel itself didn't force all buffers to be written to disk as part of the shutdown or reboot process.

In this sort of old Unix environment, you needed to sync by hand before rebooting the system to get all the dirty buffers to disk. But just one sync wouldn't necessarily do it; what you needed to do was run sync and then wait for a bit. But for some reason this was never made an explicit part of the instructions; instead people were told 'do several sync commands, typing each by hand'. This should take enough time that the buffer flush started by the first sync would have completed by the time you ran reboot (especially if you were using a slow hardcopy console terminal, which was common then).

So the right command sequence of folklore is:

# sync
# sync
# sync
# reboot

(Without typeahead, of course.)

But this mutated to just 'sync three times', so of course people started writing 'sync; sync; sync'. And then the whole mess descended into folklore and superstition. (Sometimes you see people advising that you should always run two or three syncs instead of one, even if you're not shutting down the system.)

These days it is an atrociously bad Unix system that doesn't flush all buffers on shutdown by default, so the whole 'sync before reboot' folklore is unnecessary. Often sync(2) is also synchronous (and thus the sync command too), although the other behavior is still permitted; see the Single Unix Standard sync(2) manpage.

Comments on this page:

By Matt at 2015-06-16 18:01:00:

It still feels weird to type 'reboot' without any incantation beforehand, though.

Old-timer here. Back in the glory days of TAPE, 3 rapid sync's in a row was a way to tell the TAPE controllers to not just un-link/unspool the tape-stream, but to rewind it as well, i.e. set the FD/rw-head to 0.

"sync;sync;sync" was really only used, productively, by those of us who cut our teeth with TAPE-based Unix's, i.e. apps whose files were mounted on /var/spool, the cheapest storage possible at the time. ;)

The MIPS Risc/OS operator manuals have a page on this ..

Written on 28 December 2005.
« A thought about free software licenses
What I use asserts for »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Dec 28 00:52:13 2005
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.