检测过程是否以可可中的通知开始和结束 [英] Detecting whether a process starts and finishes with notifications in 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 :!
推荐答案
对于UI流程,您可以使用NSRunningApplication。您可以观察终止的属性,以了解何时结束。您可以收听NSWorkspaceWillLaunchApplicationNotification来了解何时启动应用程序。
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.
由于您没有运行UI应用程序,因此上述操作可能无效。您将不得不使用更多低级BSD调用。下面是一个示例,您可以了解何时终止进程:
https://developer.apple.com/library/content/technotes/tn2050/_index.html#//apple_ref/doc/uid/DTS10003081- CH1-SUBSECTION10
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
祝你好运!
这篇关于检测过程是否以可可中的通知开始和结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!