Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

files on multiple processes

If one of my processes open a file, let's say for reading only, does the O.S guarantee that no other process will write on it as I'm reading, maybe leaving the reading process with first part of the old file version, and second part of the newer file version, making data integrity questionable?

I am not talking about pipes which have no seek, but on regular files, with seek option (at least when opened with only one process).

like image 782
Liran Orevi Avatar asked Apr 22 '09 19:04

Liran Orevi


1 Answers

No, other processes can change the file contents as you are reading it. Try running "man fcntl" and ignore the section on "advisory" locks; those are "optional" locks that processes only have to pay attention to if they want. Instead, look for the (alas, non-POSIX) "mandatory" locks. Those are the ones that will protect you from other programs. Try a read lock.

like image 186
Brandon Rhodes Avatar answered Sep 17 '22 17:09

Brandon Rhodes