如何在 Mac Os 上按名称获取进程? [英] How to get Get Process By Name on Mac Os?

查看:70
本文介绍了如何在 Mac Os 上按名称获取进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想获得一个进程指针并执行类似 Win32 WaitForSingleObject(hProcess, INFINITE); 的操作,如果它不为空,它将等待进程退出.如何为 Mac/Unix like Os 创建这样的 GetProcessByName 函数?

So I want to get a process pointer and do something like Win32 WaitForSingleObject(hProcess, INFINITE); that would wait for process to quit if it is not null. How to create such GetProcessByName function for Mac/Unix like Os?

推荐答案

[NSWorkspace runningApplications][NSRunningApplication runningApplicationsWithBundleIdentifier:].你可以通过 KVO 观察 NSRunningApplication 的 terminated 属性.您还可以观看通知 NSWorkspaceDidTerminateApplicationNotification.

Look at [NSWorkspace runningApplications] and [NSRunningApplication runningApplicationsWithBundleIdentifier:]. You can KVO observe NSRunningApplication's terminated property. You can also watch the notification NSWorkspaceDidTerminateApplicationNotification.

这些都是 10.6+.如果您需要早期版本,请根据您的版本要求更新您的问题.这在旧版本中是可能的,但 10.6 使它变得更容易.

These are all 10.6+. If you need earlier versions, update your question with your version requirements. It's possible in older versions, but 10.6 made it much easier.

这篇关于如何在 Mac Os 上按名称获取进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆