如何在Mac终端中找到具有"顶部"的特定进程

c1p*_*1p0 34 macos grep

我已经尝试top | grep skype了例子,但它不起作用.我试图通过名字找到一个特定的过程.

xof*_*fer 56

请改用: ps -ax | grep -i skype

  • 使用-x标志,ps应显示所有进程.你确定skype正在运行吗?试试`ps -ax | grep -i skype` (4认同)

jef*_*eff 10

使用: top -l 0 | grep Skype

0表示无限样本.您还可以将样本数限制为正数.


Ken*_*ent 6

如果你真的爱顶,你可以尝试:

top -b -n 1 | grep skype
Run Code Online (Sandbox Code Playgroud)

例如

kent$  top -b -n 1 |grep dropbox
 4039 kent      20   0  184m  14m 5464 S    0  0.4   0:58.30 dropbox
Run Code Online (Sandbox Code Playgroud)

  • 对我不起作用:top:无法识别或缺少选项b (3认同)

Dav*_*dia 6

在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`
Run Code Online (Sandbox Code Playgroud)

如果你做了很多,你可以把它变成一个函数并将其添加到 ~/.bash_profile:

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

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