jacobsa
jacobsa

Reputation: 6609

linux: is data written to a file guaranteed to be visible to other processes?

If I use write(2) to write to a file from one process on Linux and afterward open(2) and read(2) in another process, am I guaranteed to see the data I wrote without a call to fsync(2) or close(2)?

(Please ignore the possibility that the filename was unlinked or overwritten or that the system rebooted or that another process wrote data. And assume that I've correctly established an edge between the write and the read.)

I understand that the data isn't guaranteed to be persisted on disk, but is it guaranteed to be visible to the second process?

Upvotes: 5

Views: 480

Answers (1)

jacobsa
jacobsa

Reputation: 6609

The posix spec for write lays this out clearly:

If a read() of file data can be proven (by any means) to occur after a write() of the data, it must reflect that write(), even if the calls are made by different processes.

Upvotes: 8

Related Questions