Consider this pseudo-code and an ext4 file system:
f = open("/tmp/new_file", "w")
write(f, "Test")
close(f)
In another process, I try to open /tmp_newfile
immediately afterwards:
Questions
- Can the other process open the file?
- What content does the other process see? Is it
Test
?
Expectations
I expect (1) to be true (the metadata is probably synchronized between processes) but (2) to be false (data might be buffered)
More questions
- How can I ensure that my file changes are visible to other processes?
flush
seems to work but it is bad for performance because it forces a write-to-disk. Is there something likesoft-flush
that makes the changes visible to other processes without flushing it to disk?