简体   繁体   中英

Mandatory file locking in Mac OS X

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?

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

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.

Footnotes

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM