【问题标题】:How to examine processes in OS X's Terminal?如何检查 OS X 终端中的进程?
【发布时间】:2012-01-10 04:33:36
【问题描述】:

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

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

【问题讨论】:

    标签: macos process terminal ps


    【解决方案1】:

    运行ps -e 可以解决问题。找到答案here

    【讨论】:

    • 使用kill [PID] aka kill 83132 杀死想要的进程。
    • ps -e 加上grep 是我所需要的。
    • @sundaymonday 建议您将接受的答案更改为这个。
    【解决方案2】:

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

    【讨论】:

    • 运行top 只显示足够的进程来填满屏幕。它不显示“一切都在运行”。如何查看不在top可见区域内的进程@
    • Jeff,如果你想要完整的列表,你可以使用ps aux或者你可以在打开top时对进程列表进行排序,例如: 按内存使用排序:top -o rsize 按CPU排序用法:top -o cpu这不完全是整个列表,
    • 如果您想使用 top 查看所有进程的单个快照,请使用 top -l 1-l 用于“记录模式”,一个用于输出多少样本。
    【解决方案3】:

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

    您可以使用 Homebrew 安装它:

    brew install htop
    

    如果您的系统上安装了 Xcode 和相关工具(例如 git),并且您想安装来自 the official source repository 的最新开发代码,请按照以下步骤操作。

    首先从htop GitHub 仓库克隆源代码:

    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
    

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

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

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

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

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

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            【解决方案7】:

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

            man ps
            

            有一个关键字列表可让您构建所需的内容。例如显示,userid / processid / percent cpu / percent memory / work queue / command :

            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默认终端上使用它,颜色显示有点不同,但仍然很棒。

            树道

            如此处所述: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
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2014-04-15
              • 2015-10-26
              • 1970-01-01
              • 2010-10-29
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多