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
How to examine processes in OS X's Terminal?
提问by SundayMonday
I'd like to view information for processes running in OS X. Running ps
in 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 top
It will display everything running on your OSX
您可以使用top
它会显示在您的 OSX 上运行的所有内容
回答by JakeGould
Using top
and ps
is okay, but I find that using htop
is far better & clearer than the standard tools Mac OS X uses. My fave use is to hit the T
key while it is running to view processes in tree view (see screenshot). Shows you what processes are co-dependent on other processes.
使用top
和ps
没问题,但我发现使用htop
比 Mac OS X 使用的标准工具要好得多,也更清晰。我最喜欢的用途是T
在它运行时按下键以在树视图中查看进程(见截图)。显示哪些进程相互依赖于其他进程。
You can install it from Homebrew using:
您可以使用以下命令从 Homebrew 安装它:
brew install htop
And if you have Xcode and related tools such as git
installed 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 htop
GitHub repository:
首先从htop
GitHub 存储库克隆源代码:
git clone [email protected]:hishamhm/htop.git
Now go into the repository directory:
现在进入存储库目录:
cd htop
Run autogen.sh
:
运行autogen.sh
:
./autogen.sh
Run this configure
command:
运行此configure
命令:
./configure
Once the configure
process 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 ps
will give you all the options.
试试ps -ef
。man 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 top
command. 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 top
or ps
manual, as those commands have a bunch of options).
可能是您最好的选择,除非您想坚持使用终端(在这种情况下,请阅读top
或ps
手册,因为这些命令有很多选项)。
回答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 显示。试试吧。