Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

osx - How to get a process id (PID) programmatically?

How can I get a process' ID? I require the ID in order to kill that process. I know the name of the process.

Thanks!

like image 506
Alex Avatar asked Jun 02 '11 13:06

Alex


People also ask

How do I find the PID of a process on Mac?

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>.

How do you find the PID of a process?

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.

How do I find process by process ID in Linux?

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.

How do I see what processes are running on Mac terminal?

Launch Terminal (Finder > Applications > Utilities). When Terminal is running, type top and hit Return. This will pull up a list of all your currently running processes. As in the Activity Monitor, this list shows your processes in decreasing order of how much of your resources they're consuming.


1 Answers

The best approach is to use -[NSWorkspace launchedApplications] for 10.5- and -[NSWorkspace runningApplicattions] for 10.6+ apps. One returns a dictionary with specified keys, including process ID and bundle name and location info (when available), the other an NSRunningApplication object.

like image 103
nomothetis Avatar answered Sep 18 '22 20:09

nomothetis