检测其他进程何时关闭 OSX

发布于 2024-08-24 07:23:34 字数 96 浏览 3 评论 0原文

我需要一种方法来确定 Cocoa 应用程序是否正在运行给定的进程名称。我的一个想法是使用 NSTask 并使用 ps aux | poll grep 进程名.有更好的解决方案吗?

I need a way to determine from a Cocoa app if a given process name is running. One idea I had was to use NSTask and poll using ps aux | grep processName. Is there a better solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

终难愈 2024-08-31 07:23:34

您应该能够轻松地调整此示例代码以按名称查找进程:

http://developer.apple.com/mac/library/samplecode/PIDFromBSDProcessName/listing1.html

You should be able to easily adapt this sample code to look for a process by name:

http://developer.apple.com/mac/library/samplecode/PIDFromBSDProcessName/listing1.html

雪落纷纷 2024-08-31 07:23:34

如果您使用的是 Snow Leopard,则可以查看 NSRunningApplication 类,特别是 + runningApplicationWithProcessIdentifier: 方法

If you're on Snow Leopard, you could take a look at the NSRunningApplication class particularly the + runningApplicationWithProcessIdentifier: method

溇涏 2024-08-31 07:23:34

我使用了 GetBSDProcessList() 函数 几次都相当成功。

I've used the GetBSDProcessList() function quite successfully several times.

公布 2024-08-31 07:23:34

您可以使用流程管理器使用 GetNextProcess 并使用 CopyProcessName 获取进程的名称。请注意,此技术并不能解决观察进程何时启动的问题。

You can use the Process Manager API to loop through all the running processes with GetNextProcess and use CopyProcessName to get the name of the process. Note that this technique does not solve the problem of observing when a process is launched.

皇甫轩 2024-08-31 07:23:34

如果您需要检查进程是否运行一段时间(而不是瞬间),请查看 技术说明 2050:无需轮询即可观察进程生命周期。技术说明中的一些技术有 限制:它们只能让您监视当前登录会话中的 GUI 进程。 kqueues<然而, /a> 可能正是您正在寻找的:它们可以让您监视任何类型的一个进程。

If you need to check that a process is running for a duration (rather than at an instant), take a look at Tech Note 2050: Observing Process Lifetimes Without Polling. Some of the techniques in the tech note have limitations: they only let you monitor GUI processes in the current login session. kqueues, however, might be exactly what you're looking for: they let you monitor one process of any kind.

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