On 2025-07-22 23:50, Bruno Haible wrote:
it is highly desirable that output from process A is finished
in the log file before output from process B begins — otherwise the
file will contain text from process A with colour attributes from process B
or vice versa. FLUSH_ALL is designed to minimized this styling garbage.
Yes, but fsync has nothing to do with interleaving process output.
fsync arranges for a file's kernel data to hit persistent storage. If
one process calls fsync on a file descriptor, before fsync returns the
kernel persists into permanent storage all data that the kernel has
cached for the file, regardless of which process modified the data.
Although this is important if you have a database server and want to
survive power outages, it's orthogonal to what happens when processes
interleave output to the same file.
Similarly for tcdrain and ttys.
It's possible that adding calls to fsync and tcdrain can help fix some
races, as a hack. But calling 'nanosleep' can also do that hack, and
nanosleep is way cheaper than fsync.