macos 如何检查 OS X 终端中的进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8334433/
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:39:25  来源:igfitidea点击:

How to examine processes in OS X's Terminal?

macosprocessterminalps

提问by SundayMonday

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

我想查看在 OS X 中运行的进程的信息。ps在终端中运行只会列出打开的终端窗口。如何查看所有正在运行的进程?

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

假设我正在运行 Web 浏览器、终端和文本编辑器。我想查看有关文本编辑器和网络浏览器的信息。

采纳答案by camilo_u

You can just use topIt will display everything running on your OSX

您可以使用top它会显示在您的 OSX 上运行的所有内容

回答by SundayMonday

Running ps -edoes the trick. Found the answer here.

跑步ps -e可以解决问题。在这里找到了答案。

回答by JakeGould

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

使用topps没问题,但我发现使用htop比 Mac OS X 使用的标准工具要好得多,也更清晰。我最喜欢的用途是T在它运行时按下键以在树视图中查看进程(见截图)。显示哪些进程相互依赖于其他进程。

htop on OSX

OSX 上的 htop

You can install it from Homebrew using:

您可以使用以下命令从 Homebrew 安装它:

brew install htop

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

如果您git的系统上安装了Xcode 和相关工具,并且您想安装来自官方源代码库的最新开发代码 -只需按照以下步骤操作即可。

First clone the source code from the htopGitHub repository:

首先从htopGitHub 存储库克隆源代码:

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

Now go into the repository directory:

现在进入存储库目录:

cd htop

Run autogen.sh:

运行autogen.sh

./autogen.sh

Run this configurecommand:

运行此configure命令:

./configure

Once the configureprocess completes, run make:

configure过程完成后,运行make

make

Finally install it by running sudo make install:

最后通过运行安装它sudo make install

sudo make install

回答by Dave

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

试试ps -efman ps会给你所有的选择。

 -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.

回答by Macmade

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

试试这个top命令。这是一个交互式命令,将显示正在运行的进程。

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

您还可以使用 Apple 的“活动监视器”应用程序(位于/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...

它提供了一个非常漂亮的 GUI。您可以查看所有正在运行的进程,按用户对其进行过滤,获取有关它们的扩展信息(CPU、内存、网络等)、监控它们等...

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

可能是您最好的选择,除非您想坚持使用终端(在这种情况下,请阅读topps手册,因为这些命令有很多选项)。

回答by Toe

To sort by cpu usage: top -o cpu

按 CPU 使用率排序: top -o cpu

回答by Jimmy MG Lim

if you are using ps, you can check the manual

如果你使用的是ps,你可以查看手册

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 :

有一个关键字列表,可让您构建所需的内容。例如显示,用户 ID / 进程 ID / 百分比 cpu / 百分比内存 / 工作队列 / 命令:

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.

-e 类似于 -A(包括所有内容;您的进程和其他进程),而 -o 是强制格式化。

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

如果您正在寻找特定的 uid,您可以使用 awk 或 grep 链接它,例如:

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

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

这应该(几乎)只对用户 ID 501 显示。试试吧。