67

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

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

4

7 回答 7

62

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

于 2011-11-30T23:22:15.347 回答
51

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

于 2011-11-30T23:22:38.030 回答
48

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

OSX 上的 htop

您可以使用以下方法从 Homebrew 安装它:

brew install htop

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

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

git clone git@github.com:hishamhm/htop.git

现在进入存储库目录:

cd htop

运行autogen.sh

./autogen.sh

运行此configure命令:

./configure

configure过程完成后,运行make

make

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

sudo make install
于 2013-11-11T23:55:31.817 回答
19

试试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.
于 2011-11-30T23:22:20.993 回答
7

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

您也可以使用 Apple 的“活动监视器”应用程序(位于 中/Applications/Utilities/)。

它提供了一个实际上相当不错的 GUI。您可以查看所有正在运行的进程、按用户过滤它们、获取有关它们的扩展信息(CPU、内存、网络等)、监控它们等...

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

于 2011-11-30T23:22:56.953 回答
4

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

于 2013-09-05T21:27:56.500 回答
3

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

man ps

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

ps -e -o "uid pid pcpu pmem wq comm"

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

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

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

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

稍微 GUI 的方式

如果您是 cli (ui) 粉丝。我建议尝试https://github.com/clementtsang/bottom,它不仅显示进程,还显示温度、磁盘使用情况和网络。截图是从 kitty(终端)运行的,我在 OSX 默认终端上使用它,颜色显示有点不同,但仍然令人惊叹。

cli进程监视器 - 底部

树的方式

如此处所述:https ://en.wikipedia.org/wiki/Pstree将在流程的层次结构上提供更好的连接

brew install pstree     # if you need to install it
pstree
pstree -u <user>        # show only processes by your user
pstree -s <string>      # show only processes with string
pstree -help            # show help
于 2019-05-22T18:07:53.847 回答