在Mac OS X中的强制性文件锁定 [英] Mandatory file locking in Mac OS X

查看:529
本文介绍了在Mac OS X中的强制性文件锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据页以下方法仅支持咨询锁:羊群提供lockf 的fcntl 。有什么办法来强制锁的某些文件由一个单一的过程中,例如用写锁定,这样其他进程将无法打开该文件的写权限?

According to a man pages the following approaches supports only advisory locking: flock, lockf and fcntl. Is there any way to mandatory lock a some file by a single process, for example with a write lock, so that other process will not able to open this file with the write permissions?

推荐答案

没有。在UNIX系列操作系统不支持一般强制性文件锁定 1 。这包括的Linux,BSD和OS X。

No. Operating systems in the Unix family do not generally support mandatory file locking1. This includes Linux, BSD, and OS X.

在一些Unix系统,你是无法打开文件,如果它们是可执行映像当前正在运行的写pvented $ P $; 的open()将失败, ETXTBSY 。然而,你可以永远只是取消链接(删除)该文件并创建一个新的来代替,并没有将prevent这一点。

On some Unixes, you are prevented from opening files for writing if they are executable images that are currently running; open() will fail with ETXTBSY. However, you can always just unlink (delete) the file and create a new one instead, and nothing will prevent that.

1 :这是不完全正确的,但强制性文件锁需要一点的工作,强制锁是特定于平台的,和OS X对他们没有支持

1: This is not entirely true, but mandatory file locks require a bit of work, mandatory locks are platform-specific, and OS X has no support for them.

这篇关于在Mac OS X中的强制性文件锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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