29

Top processes sorted by CPU usage

Posted in System by matt 3643 days ago

This geeklet displays the top 12 processes sorted by their CPU usage. It updates every 30 seconds.

The three columns it shows are given by "command %cpu %mem." You can delete one of those if you don't want it. You can change "head -13" at the end of the command to specify how many processes to show.

Command:

ps -arcwwwxo "command %cpu %mem" | grep -v grep | head -13

Font: Courier
Colour: White
Size: 11

Screenshot

Geeklet files to download

Comments

User Avatar
maelcum 3632 days ago
Why the 'grep -v grep'?

ps -amcwwwxo "command %cpu %mem" | head -13

works nicely for me.
User Avatar
matt 3613 days ago
Ah, oops. While I was playing around with different versions of the script I had grep -v grep to remove grep from the list if it appears. As you say, it's completely unnecessary in the script as it is above.
User Avatar
llorban 3553 days ago
How did you get the columns to show in such an orderly fashion? Each line on mine is offset

edit: I see now you used courier font
User Avatar
orbited 3332 days ago
Thanks for this! However, I use it to monitor a remote server via SSH and execute:

ssh user@whatever.server 'ps -arcwwwxo "command %cpu %mem" | grep -v grep | head -13'

Doing this also means that the ssh daemon peaks at every update. Is there anyway to make the output strip any line with "sshd" before displying the results?
User Avatar
matt 3000 days ago
Try adding `| grep -v sshd |` in the middle
User Avatar
orbited 3332 days ago
Never mind the above - Google is my friend! :)

ssh user@whatever.server 'ps -arcwwwxo "command %cpu %mem" | grep -v grep | grep -v "^sshd" | head -13'
User Avatar
ryjacs 3038 days ago
Is there a way to change the font and still have the columns aligned?
User Avatar
matt 3000 days ago
Any "fixed width" font will be fine. That restricts you a bit, but there are a fair few. Menlo is one of my favourites.
User Avatar
kbrabbit3 2821 days ago
Hey Matt - After looking at your neatly laid out ps display, I thought of colorizing it:

http://www.macosxtips.co.uk/geeklets/system/top-processes-sorted-by-cpu-usage/

I hope you don't mind me borrowing your idea. If you do, let me know and I will delete my post.
User Avatar
c45p31 2611 days ago
Ot's nice, but why not using top?

top -l 2 -n 20 -stats command,cpu,vsize

Log in to comment or register here.