Reading file that hasn't saved to disk yet

36 Views Asked by At

My scenario goes as follows:

I use one process to write new file, and close it when done. another process open this file for reading right after the first process is done. Needless to say, both processes reside on the same client.

My working platform is OS X which uses HFS+ filesystem.

According to close man page :

A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. It is not common for a file system to flush the buffers when the stream is closed. If you need to be sure that the data is physically stored use fsync(2). (It will depend on the disk hardware at this point.)

This means that the file won't necessarily save to disk. however, I only care about coherency when reading the file after it was closed, and i'd refrain from using fsync since it's very time-consuming.

Is it guaranteed that the second process read the updated data from cache even-though it wasn't flushed to disk yet?

0

There are 0 best solutions below