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?

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...