检测进程是否通过 cocoa 中的通知启动和结束
我想知道是否有一种方法可以在 /usr/sbin 中的系统进程启动和完成时收到通知。是否可以将 NSTask 附加到正在运行的进程而不启动新进程?最好不要轮询:!
I was wondering if there was a way that I could get notifications of when a system process from /usr/sbin starts and finishes. Is it possible to attach NSTask to the running process without launching a new one? Preferably without polling please :!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 UI 进程,您可以使用 NSRunningApplication。您可以观察“termied”属性来了解它何时完成。您可以收听 NSWorkspaceWillLaunchApplicationNotification 以了解应用程序何时启动。
由于您没有运行 UI 应用程序,上述内容可能不起作用。您将不得不使用更多低级 BSD 调用。以下是如何知道进程何时终止的示例:
https: //developer.apple.com/library/content/technotes/tn2050/_index.html#//apple_ref/doc/uid/DTS10003081-CH1-SUBSECTION10
祝你好运!
For UI process you can use NSRunningApplication. You can observe the "terminated" property to know when it finishes. You can listen to NSWorkspaceWillLaunchApplicationNotification to know when an application will be launched.
Since you're not running a UI application the above probably won't work. You'll have to use more low level BSD calls. Here's an example of how you can know when an process terminates:
https://developer.apple.com/library/content/technotes/tn2050/_index.html#//apple_ref/doc/uid/DTS10003081-CH1-SUBSECTION10
Good luck!