0

A process running on Linux writes some data to a file on the file system, and then invokes close(). Immediately afterwards, another process invokes open() and reads from the file.

Is the second process always 100% guaranteed to see an updated file? What happens when using a network filesystem, and the two processes run on the same host? What happens when the two processes are on different hosts?

crusaderky
  • 2,552
  • 3
  • 20
  • 28
  • 2
    Notably for network filesystems, it depends upon the file system (in case of NFS, depends upon the version, and the mount mode). For local good enough filesystem and same hosts, things are safe. – Basile Starynkevitch Feb 12 '15 at 20:19
  • @BasileStarynkevitch I'm reading through the NFS docs but I can't find it? I found sync/async but I understant that's about fsync'ing the data to physical storage rather than making it available to other hosts? – crusaderky Feb 12 '15 at 20:30

1 Answers1

0

close() does not guarantee that the data is written to disk, you have to use fsync() for this. See Does Linux guarantee the contents of a file is flushed to disc after close()? for a similar question.

user2804197
  • 354
  • 5
  • 13
  • 1
    fsync() guarantees that the file is stored persistently in case of power loss or kernel panic. My question is about two processes writing to and from the kernel cache. – crusaderky Feb 12 '15 at 20:22