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?
One very useful command to help find a process by name or PID is grep which can filter out the desired information. It can be used in conjunction with the ps -ax command to list only the process that you are interested in. For example: At the command prompt type ps -ax | grep <application name>.
Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column.
A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system. The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
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.
These days, pgrep -n $APPLICATION_NAME
seems like the easiest way to accomplish this. From the man page:
-n Select only the newest (most recently started) of the matching processes.
-o Select only the oldest (least recently started) of the matching processes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With