检测进程是否通过 cocoa 中的通知启动和结束

发布于 2024-09-07 18:05:22 字数 88 浏览 0 评论 0原文

我想知道是否有一种方法可以在 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛时过境迁 2024-09-14 18:05:22

对于 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文