How to get the process id (PID) of an app launched using `open` command on OSX?

隐身守侯 提交于 2020-01-14 09:07:04

问题


I've launched an application via the open command on the OSX command line like so:

open -a "/Applications/Adobe After Effects CC/Adobe After Effects CC.app"

I want to get the process id of that launched application. Is there any way to do this reliably on OSX? It doesn't seem open returns anything, so I'm not sure I can even pipe its result into something like ps to perform a grep operation. I thought that maybe since the app is launched via the terminal I would know which app is the frontmost, but am doubting the reliability of that solution. Any ideas?


回答1:


After executing open -a, you can execute ps command. Doing a grep on the output of ps command gives info on process ID.

ps aux | grep -v grep |grep -i <application name> | awk '{print $2;}'

The one given below gives the elapsed time for the process.

ps aux -o etime,command | grep -v grep |grep -i <application name> | awk '{print $2, $12,$13}'

We can compare the elapsed time to know the pid of the recently launched one.



来源:https://stackoverflow.com/questions/25389495/how-to-get-the-process-id-pid-of-an-app-launched-using-open-command-on-osx

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