5 ms·
And specifically when you tell the shell to redirect stdout to a file, the shell is opening a file descriptor to handle the request. A file descriptor also sits
by bpoyner 3y ago
And specifically when you tell the shell to redirect stdout to a file, the shell is opening a file descriptor to handle the request. A file descriptor also sits in the middle for piping stdout for one command to stdin of another. It seems like it's doing magic, but it's not.
- passion__desire 3y agoAre we continuously told in our courses to flush() the file so that it gets written to disk?
- bcrl 3y agoIf you're talking about fflush() from the C standard libray, fflush() doesn't write to disk. It pushes writes from the FILE's buffer to the kernel and drops any read data that has been cached. The C standard library doesn't really provide you with all the tools needed to commit writes to disk fully.
- 95014_refugee 3y agoHopefully not, because that murders performance. The caching exists for a reason, let it do its thing. If you care about data integrity, you don’t trust the disk anyway, so flushing to the disk isn’t enough.
- Filligree 3y agoThere's fsync. Unfortunately, if you want atomicity but not durability you have ~zero options on common filesystems. (On ZFS and bcachefs you can get that by disabling syncs completely; they never reorder writes in a visible manner.)