文件在多个进程上 [英] files on multiple processes
问题描述
如果我的一个进程打开一个文件,让我们说只读,操作系统保证没有其他进程会写在它上面,也许
离开阅读过程的第一部分旧文件版本和新文件版本的第二部分,使数据完整性有问题?
我不是在讨论没有寻求的管道,而是在普通文件上(至少在打开时只有一个进程)。
不,其他进程可以更改文件内容阅读它。尝试运行man fcntl和忽略
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).
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.
这篇关于文件在多个进程上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!