How can I find a specific process with "top" in a Mac terminal

On Linux, the top command supports the -p option to monitor specific PIDs. On MacOS, the -p option is called -pid instead.

# Get the PID of the process
pgrep Skype

# Then
top -pid <put PID here>

# Or more succinctly:
top -pid `pgrep Skype`

If you do this a lot, you could turn this into a function and add it to ~/.bash_profile:

# Add this to ~/.bash_profile
function topgrep() {
    if [[ $# -ne 1 ]]; then 
        echo "Usage: topgrep <expression>"
    else 
        top -pid `pgrep $1`
    fi
}

Now you can simply use topgrep Skype instead, which will run like usual but it will only show the process(es) matching expression.


Use this instead: ps -ax | grep -i skype


Use: top -l 0 | grep Skype

The 0 is for infinite samples. You can also limit the number of samples to a positive number.


if you really love top, you could try:

top -b -n 1 | grep skype

e.g.

kent$  top -b -n 1 |grep dropbox
 4039 kent      20   0  184m  14m 5464 S    0  0.4   0:58.30 dropbox

Tags:

Macos

Grep