writing to disk with O_SYNC

write(2) doesn’t actually write to disk imediatelly. Instead, it writes to a page cache and the OS periodically handles writes to disk. Using O_SYNC, though, write(2) returns only when it fully wrote the data to a data block. Linux exposes the actual timeframe for periodic writings:

➜  ~ cat /proc/sys/vm/dirty_writeback_centisecs 
500

source and export diff

Non-interactive shells don’t load initialization files, so bash -c ‘declare -f’ doesn’t output anything. But we can source it: bash -c ‘source ~/.bashrc; hello’. Or even: bash -c ‘hello() { echo “hi”; }; declare -f’. It’s all about memory share in shell modes: source changes only affect current shell memory. export marks variables to be passed to child processes. Subtile difference that can save us a lof of debugging time.