简体   繁体   English

如何在Mac OSX上监视进程/应用程序或文件锁定?

[英]How do I monitor processes/apps or file locks on Mac OSX?

I'm porting a file encryption app from Windows to Mac OSX. 我正在将文件加密应用程序从Windows移植到Mac OSX。 One of its features, is that it lets you open an encrypted file in its source application (say TextEdit), make some changes and then re-rencrypt the file. 它的功能之一是,它允许您在其源应用程序(例如TextEdit)中打开一个加密文件,进行一些更改,然后重新加密该文件。

To accomplish this on OSX, I would like to either monitor the start/stop of the process that is launched when I ask the system to open my decrypted document, or monitor the file itself for any acquired and released locks. 为了在OSX上完成此操作,我想监视当我要求系统打开解密的文档时启动的进程的开始/停止,或者监视文件本身是否存在任何已获得和释放的锁。

Is there a way to programatically accomplish this, either through existing OSX or Unix APIs? 是否可以通过现有的OSX或Unix API以编程方式完成此任务? I've already tried the .NET provided APIs (FileSystemWatcher, Process) without luck. 我已经尝试过.NET提供的API(FileSystemWatcher,Process),但没有碰到运气。

What I wound up doing, was to listen to Notifications from NSNotificationCenter and NSApplication after I had asked the OS to open my file in its default Application. 我最后要做的是,在我要求操作系统在其默认应用程序中打开文件后,听听来自NSNotificationCenterNSApplication通知。 The particular events were: 具体事件是:

  • NSWorkspace.Notifications.ObserveDidLaunchApplication(EventHandler)
  • NSWorkspace.Notifications.ObserveDidTerminateApplication(EventHandler)

If you're stuck with the same issue, please see my implementation here . 如果您遇到同样的问题,请在此处查看我的实现

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

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