如何在顶部显示用户名?

如何在顶部显示用户名?

我想做类似的事情top -o cpu,但每行显示每个进程的用户名。我该怎么做?谢谢!

ps 我在 Mac OS 上。我不确定该top命令是否与其他非 BSD 不同。

答案1

笔记此解决方案仅适用于 Mac OS。Linux 版本有显著差异。

top默认情况下不显示用户名,只显示 UID。

您可以选择使用该选项显示哪些列-stats

例如

top -stats pid,user,cpu,command

将显示进程 ID、用户名、CPU 使用率和命令

Processes: 167 total, 2 running, 4 stuck, 161 sleeping, 828 threads                                                                                                                                       09:55:43
Load Avg: 0.99, 1.31, 1.72  CPU usage: 7.6% user, 12.7% sys, 80.86% idle    SharedLibs: 11M resident, 10M data, 0B linkedit. MemRegions: 46953 total, 2034M resident, 55M private, 708M shared.
PhysMem: 1166M wired, 2962M active, 849M inactive, 4977M used, 3213M free. VM: 402G vsize, 1054M framework vsize, 13229803(2) pageins, 816120(0) pageouts.
Networks: packets: 909991873/986G in, 888624532/347G out. Disks: 35379646/317G read, 10360185/448G written.

PID                                              USER                                                     %CPU                                           COMMAND
89849                                            root                                                     0.0                                            installd
87409                                            corti                                                    0.0                                            cookied
75165                                            root                                                     8.4                                            top
75163                                            corti                                                    0.0                                            mdworker

您可以使用以下命令查看列表man top

          pid    Process ID (default).

          command
                 Command name.

          cpu    CPU usage.

          csw    Number of context switches.

          time   Execution time.

          threads
                 alias: th
                 Number of threads (total/running).

          ports  alias: prt
                 Number of Mach ports.

          mregion
                 alias: mreg, reg
                 Number of memory regions.

          rprvt  Resident private address space size.

          rshrd  Resident shared address space size.

          rsize  Resident memory size.

          vsize  Total memory size.

          vprvt  Private address space size.

          kprvt  Private kernel memory size.

          kshrd  Shared kernel memory size.

          pgrp   Process group id.

          ppid   Parent process id.

          state  alias: pstate
                 Process state.

          uid    User ID.

          wq     alias: #wq, workqueue
                 The workqueue total/running.

          faults alias: fault
                 The number of page faults.

          cow    alias: cow_faults
                 The copy-on-write faults.

          user   alias: username Username.

          msgsent
                 Total number of mach messages sent.

          msgrecv
                 Total number of mach messages received.

          sysbsd Total BSD syscalls.

          sysmach
                 Total Mach syscalls.

          pageins
                 Total pageins.

相关内容