macos 如何在 Mac 终端中找到带有“top”的特定进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7501057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:27:08  来源:igfitidea点击:

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

macosgrep

提问by c1p0

I've tried top | grep skypefor example but it doesn't work. I'm trying to find a specific process by name.

top | grep skype例如,我已经尝试过,但它不起作用。我正在尝试按名称查找特定进程。

回答by xofer

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

改用这个: ps -ax | grep -i skype

回答by jeff

Use: top -l 0 | grep Skype

利用: top -l 0 | grep Skype

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

0 代表无限样本。您还可以将样本数限制为正数。

回答by Kent

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

回答by Dave Ceddia

On Linux, the topcommand supports the -poption to monitor specific PIDs. On MacOS, the -poption is called -pidinstead.

在 Linux 上,该top命令支持-p监控特定 PID的选项。在 MacOS 上,-p-pid改为调用该选项。

# 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:

如果你经常这样做,你可以把它变成一个函数并将它添加到 ~/.bash_profile

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

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

现在您可以简单地topgrep Skype改用它,它会像往常一样运行,但只会显示匹配的进程expression

回答by Heisenbug

use psinstead of top.

使用ps而不是 top。

回答by seantomburke

Now you can use pgrep skypeto find the process.

现在您可以使用pgrep skype来查找进程。

回答by Brad Johnson

I would recommend using ps -ax | less

我建议使用 ps -ax | less

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

在 中less,您可以输入/skypeEnter以搜索名称包含“skype”的进程。

回答by André Portela

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

在 MacOSX Mojave 上测试。它的工作原理与 linux 有点不同。

top -piddoesn'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不需要逗号分隔的 pid 列表,它只需要一个 pid。所以我不得不稍微改变它以使用几个pid。

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

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

在顶部过滤所有 Python 进程。它本质上变成了这样:

top -pid 123 -pid 836 -pid 654