开发者

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

I've tried top | grep skype for example but it doesn't w开发者_开发问答ork. I'm trying to find a specific process by name.


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.


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.


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


use ps instead of top.


Now you can use pgrep skype to find the process.


Tested on MacOSX Mojave. It works a bit different than linux.

top -pid doesn't expect a comma separated list of pids, it expects only one pid. So I had to changed it a little to work with several pids.

top -pid $(pgrep -d ' -pid ' -f Python)

filter all Python process on top. It essentially becomes something like this:

top -pid 123 -pid 836 -pid 654


I would recommend using ps -ax | less

From within less, you can type in /skypeEnter to search for processes with names containing "skype".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜