How to examine processes in OS X's Terminal?

MacosProcessTerminalPs

Macos Problem Overview


I’d like to view information for processes running in OS X. Running ps in the terminal just lists the open Terminal windows. How can I see all processes that are running?

Say I’m running a web browser, terminal and text editor. I’d like to see information for the text editor and web browser.

Macos Solutions


Solution 1 - Macos

Running ps -e does the trick. Found the answer here.

Solution 2 - Macos

You can just use top It will display everything running on your OSX

Solution 3 - Macos

Using top and ps is okay, but I find that using htop is far better & clearer than the standard tools Mac OS X uses. My fave use is to hit the T key while it is running to view processes in tree view (see screenshot). Shows you what processes are co-dependent on other processes.

htop on OSX

You can install it from Homebrew using:

brew install htop

And if you have Xcode and related tools such as git installed on your system and you want to install the latest development code from the official source repository—just follow these steps.

First clone the source code from the htop GitHub repository:

git clone [email protected]:hishamhm/htop.git

Now go into the repository directory:

cd htop

Run autogen.sh:

./autogen.sh

Run this configure command:

./configure

Once the configure process completes, run make:

make

Finally install it by running sudo make install:

sudo make install

Solution 4 - Macos

Try ps -ef. man ps will give you all the options.

 -A      Display information about other users' processes, including those without controlling terminals.

 -e      Identical to -A.

 -f      Display the uid, pid, parent pid, recent CPU usage, process start time, controlling tty, elapsed CPU usage, and the associated command.  If the -u option is also used, display
         the user name rather then the numeric uid.  When -o or -O is used to add to the display following -f, the command field is not truncated as severely as it is in other formats.

Solution 5 - Macos

Try the top command. It's an interactive command that will display the running processes.

You may also use the Apple's "Activity Monitor" application (located in /Applications/Utilities/).

It provides an actually quite nice GUI. You can see all the running processes, filter them by users, get extended informations about them (CPU, memory, network, etc), monitor them, etc...

Probably your best choice, unless you want to stick with the terminal (in such a case, read the top or ps manual, as those commands have a bunch of options).

Solution 6 - Macos

To sort by cpu usage: top -o cpu

Solution 7 - Macos

if you are using ps, you can check the manual

man ps

there is a list of keywords allowing you to build what you need. for example to show, userid / processid / percent cpu / percent memory / work queue / command :

ps -e -o "uid pid pcpu pmem wq comm"

-e is similar to -A (all inclusive; your processes and others), and -o is to force a format.

if you are looking for a specific uid, you can chain it using awk or grep such as :

ps -e -o "uid pid pcpu pmem wq comm" | grep 501

this should (almost) show only for userid 501. try it.

The slightly GUI way

if you are a cli (ui) fan. I recommend trying https://github.com/clementtsang/bottom which shows not only processes, but also temperature, disk usage and network. Screenshot is running from kitty (terminal) as an example, I use it on OSX default terminal and the color shows up a bit different, but still amazing.

cli process monitor - bottom

The tree way

As described here : https://en.wikipedia.org/wiki/Pstree will give a better connection on the hierarchy of the processes

brew install pstree     # if you need to install it
pstree
pstree -u <user>        # show only processes by your user
pstree -s <string>      # show only processes with string
pstree -help            # show help

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSundayMondayView Question on Stackoverflow
Solution 1 - MacosSundayMondayView Answer on Stackoverflow
Solution 2 - Macoscamilo_uView Answer on Stackoverflow
Solution 3 - MacosGiacomo1968View Answer on Stackoverflow
Solution 4 - MacosDaveView Answer on Stackoverflow
Solution 5 - MacosMacmadeView Answer on Stackoverflow
Solution 6 - MacosToeView Answer on Stackoverflow
Solution 7 - MacosmirageglobeView Answer on Stackoverflow