2018年4月1日 星期日

[Linux 常見問題] Show top five CPU consuming processes with `ps`

Source From Here 
Question 
How to show top five CPU consuming processes with ps? 

How-To 
Why use ps when you can do it easily with the top command? If you must use ps, try this: 
// For sort command argument:
// -n, --numeric-sort: compare according to string numerical value
// -r, --reverse: reverse the result of comparisons
// -k, --key=KEYDEF
// sort via a key; KEYDEF gives location and type

# ps aux | sort -nrk 3,3 | head -n 5

If you want something that's truly 'top'esq with constant updates, use watch
# watch "ps aux | sort -nrk 3,3 | head -n 5" // Sort by CPU usage decreasingly

Again, if you are using top command, you can use option "-o" to decide the column to do sorting: 
# top -o %MEM // Sorting by memory usage

Or you can after executing top command and then enter "Shift+F" to enter another screen to adjust the display column(s) or sorting order. (reference

Supplement 
How To Use The Linux Top Command To Show Running Processes 
How to display `top` results sorted by memory usage in real time?

沒有留言:

張貼留言

[ JS 常見問題 ] Javascript Date output formatting

Source From  Here   Question   I need to  capture the Now() date and time in the YYYY/mm/dd hh:m:sec format . It needs to be in GMT time. Ho...