sri commented that he runs sync(1) 57 times before rebooting, which prompted me to run strace(1) on sync, notice that sync executes 98 system calls, grumble in disgust, and cry.

The overhead was mostly in dynamically linking in libc and some locale junk, so my first attempt at improvement was just a simple:

int main () { sync (); return 0; }

Which I compiled with -static and ran with a fixed locale. This still used 12 or so syscalls. Far from the ideal two.

The world's greatest sync, however, came on my second attempt, this time in assembly:

.globl _start
movl $36, %eax
int $0x80
movl $1, %eax
int $0x80

Yah, baby. This is what I train for. Compile via

gcc -s -nostdlib sync.S -o sync

Four instructions versus 1,938. Three hundred sixty bytes versus 17 kilobytes. Two system calls versus 98. One millisecond execution versus 32.

shaver says that I suck because if I hand write an optimal ELF preamble, I can get the object size down to well under 100 bytes. Well, ladies and gentlemen, I accept patches. In the meantime, I encourage everyone to replace their gross and bloated sync with this one of stunning beautiful and uncanny ingenuity.