简体   繁体   English

如何在osx中​​使用open()文件,以便其他线程无法删除它?

[英]How to use open() a file in osx so that other threads can't remove it?

我想在我的应用程序中实现文件级锁定。

In short: 简而言之:

fd = open( "./foo", O_RDWR + O_EXLOCK);

But you first need to check if your fs supports it, see Exclusive File Access in Mac OS X . 但是,你首先需要检查你的FS支持它,请参阅在Mac OS X专用文件访问 If not, you can lock 'by convention', using for example a lock file. 如果没有,您可以使用“锁定文件”来“按惯例”锁定。 This is explained in the article. 在文章中对此进行了解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在OSX上使用emacs-live配置打开任何文件 - Can't open any file with emacs-live configuration on OSX electroJS / OSX-用我的应用程序打开文件,如何使用Apple事件? - electronJS / OSX - open file with my application, how to use the Apple event? OSX kext:由于其他所有者拥有,因此无法在:: start()中打开IOResouces - OSX kext: Can't open IOResouces in ::start() due to owned by some other 流式传输 ZIP 文件不会在 OSX 中打开 - Streaming ZIP file won't open in OSX 如何在OSX中打印.so文件的符号列表? - How to print symbol list for .so file in OSX? 无法打开文件“django-admin.py”:没有这样的文件或目录 - Mac OSX - Can't open file “django-admin.py”: No such file or directory — Mac OSX OSX终端在启动时给出消息“ Python:无法打开文件'=':[Errno 2]没有这样的文件或目录” - OSX terminal giving the message “Python: can't open file '=': [Errno 2] No such file or directory” upon startup 如何在OSX上使用MonoDevelop 2.2进行T4模板化 - How can I use T4 templating with MonoDevelop 2.2 on OSX 如何从OSX Leopard卸载python以便我可以使用MacPorts版本? - How do I uninstall python from OSX Leopard so that I can use the MacPorts version? 在Mac OSX上如何将脚本文件与终端关联,以便双击图标启动终端? - On Mac OSX how can I associate a script file with Terminal so double clicking the icon launches Terminal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM