开发者

Detecting whether a process starts and finishes with notifications in cocoa

I was wondering if there was a way that I could get notifications of when a system proce开发者_开发技巧ss 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 :!


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜