Sort top by CPU Usage to Make it More Useful

May 13, 2011 - 4 Comments

How to sort top command by CPU Use

The top command is a great way to get a quick overview of how your system is performing and how apps are using your resources. If you are unfamiliar with it, it’s basically a command line task manager like Activity Monitor and it shows processor usage, memory usage, disk activity, load average, and other helpful system resource details. A common complaint with top is that by default the apps settings don’t sort processes by CPU use, which for many of us is one of the most useful ways to detect an errant process or to keep track of system resources. Fortunately, thanks to a few easy customizations to the top command, you can quickly run top to monitor all processes from the command line and sort them by CPU use from top to bottom.

How to Sort “top” Command by CPU Usage

The simplest trick to sort top by processor utilization is by adding the -u flag to the command, like so:

top -u

The top command running with -u for CPU priority looks like the following, processes will move up and down in the list depending on their CPU usage:

top running sorted with cpu priority

Another approach to sort by cpu (or anything else) is to use the -o flag then the modifier to sort by, in this case it would be ‘cpu’ since we wish to sort by processor usage.

top -o cpu

sort top processes by CPU

Alternatively, if top isn’t doing it for you, you could just install htop for Mac OS X through MacPorts or Homebrew. htop is superior to top in many ways, but because it requires additional software to install many users might not want to bother with it, whereas ‘top’ command is included in every version of Mac OS X and just about every linux and BSD release every imaginable.

Know of any other handy top tricks? Let us know in the comments.

.

Related articles:

Posted by: William Pearson in Command Line, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. glonek says:

    Wow, thanks a billion for this info! Top author should be ashamed for not providing any of this.

  2. Bigmoof says:

    Or while in top, you can interactively sort the order by pressing o, then the key, e.g. press ocpu gets ordering by CPU usage. Other e.g. keys :

    pid
    command
    time
    ports
    uid
    vsize
    ppid

    etc.

  3. Antoine says:

    ‘top -u’ is shorter and does the job.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site