ps -eo user,pcpu,pid,cmd | sort -r -k2 | head -6
What the heck does that do?
It gives me this output:
USER %CPU PID CMD
greg 6.7 5901 /usr/lib/firefox-3.0/firefox
root 1.5 5441 /usr/bin/X :0 -br -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7
greg 0.5 7216 /usr/bin/liferea-bin
greg 0.1 7401 gnome-terminal
greg 0.1 5790 gnome-panel --sm-client-id default1
(results will vary)
This is a list of the top five most processor hungry applications running on my system right now.
ps stands for “processor stuff” and it returns stuff about the processor.
The e option tells ps to look at every process running on the system.
The o option allows the user to specify which of the many columns of data ps can produce.
The output of the ps command is piped, using the pipe symbol “|” to the sort command.
Sort takes a file or a stream of data (same thing, really) and … sorts it!
The r option sorts it in reverse. The k option tells sort which column to sort on (columns are defined by, say, the spaces between words and stuff) …. so here we are sorting on the second column.
The output of sort is then piped to the head command. The head command takes the top ten lines (the head) of a file and sends it back out again (‘head’ is a filter). But if you give it a number, it put out that number of lines.
Since ps puts out a row of column headers, to get the most processor intensive processes we ask head to give us 6 lines.
(Oh, it’s actually “processor snapshot”)