Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to do something like top -o cpu but with usernames for each process shown in each row. How can I do this? Thanks!

p.s. I am on Mac OS. I am not sure if the top command is different from other non-BSD.

share|improve this question
The linux man-page for top here indicates that the output of the command contains UID, perhaps you can use this information to obtain the username as indicated in this forum post. Not sure how easy its would be to automate the entire thing... – Bhargav Bhat Sep 8 '12 at 7:42
up vote 2 down vote accepted

Note This solution is Mac OS specific. The Linux version is significantly different.

top does not show the username by default just the UID.

You can choose which columns to show with the -stats option.

For example

top -stats pid,user,cpu,command

will show the process ID, the user name, the CPU usage and the command

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

You can see the list with man top:

          pid    Process ID (default).

                 Command name.

          cpu    CPU usage.

          csw    Number of context switches.

          time   Execution time.

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

          ports  alias: prt
                 Number of Mach ports.

                 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.

                 Total number of mach messages sent.

                 Total number of mach messages received.

          sysbsd Total BSD syscalls.

                 Total Mach syscalls.

                 Total pageins.
share|improve this answer
thanks for the quick response! – ceiling cat Sep 8 '12 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .