文件在多个进程上 [英] files on multiple processes

查看:114
本文介绍了文件在多个进程上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的一个进程打开一个文件,让我们说只读,操作系统保证没有其他进程会写在它上面,也许
离开阅读过程的第一部分旧文件版本和新文件版本的第二部分,使数据完整性有问题?

我不是在讨论没有寻求的管道,而是在普通文件上(至少在打开时只有一个进程)。

解决方案

不,其他进程可以更改文件内容阅读它。尝试运行man fcntl和忽略锁定部分;这些是可选的锁,只有在需要的时候才需要注意。相反,寻找(唉,非POSIX)强制性的锁。这些是保护你免受其他程序的伤害。尝试阅读锁。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆