检测由其他进程使用的文件 [英] Detect file in use by other process
问题描述
在窗口等,我曾经使用一个技巧找出一个文件是目前正在使用(具体写)。
我使用打开文件进行写入,如果大多数likey失败,另一个进程正忙于访问它。
很抱歉,这些伎俩(使用C OPEN与独占锁写作)不能在我的Mac上工作。虽然我的curl在终端仍在写我的-fileBusy()检查失败。
使用F_GETLK对fd执行fcnt调用也不会显示任何锁定。
我有机会检测文件是否被另一个进程使用?
侦听fsevents不能做,因为我的应用程序启动后,由其他应用程序/进程创建。
Apple通过电子邮件确认以下链接中描述的解决方案是有效的解决方案, p>
详细资讯:
http://lists.apple.com/archives/cocoa-dev/2010/May/msg01455.html
On windows and such I used to use a trick to find out of a file is currently in use (written specifically).
I use to open the file for writing and if it failed most likey another process is busy accessing it.
Sadly these trick (using C OPEN with exclusive lock for writing) doesn't work on my Mac. While my curl in a terminal is still writing my -fileBusy() check fails.
fcnt call on the fd with F_GETLK doesn't reveal any locking as well.
Is there any chance for me to detect if a file is in use by another process?
Ps> listening for fsevents can't be done because my app launches after the is created by the other app / process.
Apple confirmed via email that the solution described in the link below is a valid one and not considered a private API.
More information: http://lists.apple.com/archives/cocoa-dev/2010/May/msg01455.html
这篇关于检测由其他进程使用的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!