Looking at the changes to Snow Leopard’s top command
Mac OS X Hints
By Rob Griffiths, Macworld
I often use top in Terminal as a quick-and-dirty version of Activity Monitor. top can report on CPU and memory usage, and much more. Because I have Terminal running all the time, top is only a few keystrokes away when I’m curious about what my system may be up to.
In OS X 10.5, I used top -u 10 regularly; the -u flag sorts by CPU usage, and the 10 restricts the output to 10 processes. This gave me a quick snapshot of the top CPU usage hogs on my Mac. I used this command so often in 10.5 that I had set it as an alias; I just needed to type t10 to run it.
In 10.6, though, this command fails, and fails miserably, because top has been updated to a much newer version (the 10.5 version of top is dated September 25, 2008; the 10.6 version is dated June 25, 2009.)
In the new version of top, many of the runtime options have changed, including -u (which is now used to specify a username). You can find out more about the new version by typing man top in Terminal.
In case you’d just like the easy way to recreate my simple CPU usage tracker from 10.5, the 10.6 version of the command is:
top -o CPU -n 10
Now that I have the above command assigned to my t10 alias, everything works as it did in 10.5.
In addition to the changed runtime options, Mac OS X Hints contributor felix-fi points out a useful new feature in the 10.6 version of top: it’s now dynamic.
In 10.5, if you started top and resized the Terminal window, nothing would happen—top would just continue to display the same columns as it did when you launched it.
In 10.6, though, top will show additional data as you expand the Terminal window—make it wide enough, and eventually you’ll see 26 separate columns of data.
On my 15-inch MacBook Pro, seeing all the columns requires reducing the font size to the edge of readability, and making the window the full width of the screen.
You’ll find definitions for each column by browsing man top; COW, for instance, is the column that contains “copy on write faults,” not some obscure reference to Clarus the Dogcow.
If you want to run top and have it only show certain columns, you can do that with the -stats option. For instance, this command will show processes in descending order of CPU usage, displaying only the process ID, command name, and CPU usage:
top -o CPU -stats PID,COMMAND,CPU
After adjusting to the changes, I’ve found the 10.6 version of top to be a great improvement over its predecessor.