How to get Get Process By Name on Mac Os?

我与影子孤独终老i 提交于 2019-12-11 14:09:43

问题


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?


回答1:


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

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.




回答2:


You can only wait for a child process anyway, and if it's a child process you would have its PID (I never forget the names of my children; just their birthdays).

See: waitpid(2)



来源:https://stackoverflow.com/questions/11780718/how-to-get-get-process-by-name-on-mac-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!