Billy Noyes
Billy Noyes

Reputation: 113

Explain how this command finds the 5 most CPU intensive processes

If I have the command

ps | sort -k 3,3 | tail -n 5

How is this find the 5 most CPU intensive processes?

I get that it is taking all the processes, sorting them based on a column through the -k option, but what does 3,3 mean?

Upvotes: 0

Views: 62

Answers (1)

NeverGoodEnough
NeverGoodEnough

Reputation: 352

You could read what you seek for from the official manual of sort (info sort in linux); in particular, you are interested in the following extracts:

‘-k POS1[,POS2]’
‘--key=POS1[,POS2]’
     Specify a sort field that consists of the part of the line between
     POS1 and POS2 (or the end of the line, if POS2 is omitted),
     _inclusive_.

and, skipping a few paragraphs,

 Example: To sort on the second field, use ‘--key=2,2’ (‘-k 2,2’).
 See below for more notes on keys and more examples.  See also the
 ‘--debug’ option to help determine the part of the line being used
 in the sort.

So, basically, 3,3 emphasises that only the third column shall be considered for sorting, and the others will be ignored.

Upvotes: 1

Related Questions