bash top 命令以降序显示 %cpu
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23956628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Top command to show the %cpu in descending order
提问by Azaksai
I would like to have the cpu percentage in decending order. When I give the command :
我想按降序排列 cpu 百分比。当我发出命令时:
top -bn 1 | grep "^ " | awk '{ printf("%-8s %-8s \n", , ); }' | head -8
It shows processes which are not the top most using CPU.
它显示了不是使用 CPU 最多的进程。
回答by Andrew Cassidy
Run top as a process (I'm using Ubuntu 14.04)
作为进程运行 top(我使用的是 Ubuntu 14.04)
top
Once in top...
一旦在顶部...
P <- Sort by CPU usage
P <- 按 CPU 使用率排序
M <- Sort by MEM usage
M <- 按 MEM 使用排序
z <- Add cool visual colors
z <- 添加酷炫的视觉色彩
x <- Highlight column you are currently sorting by
x <- 突出显示您当前正在排序的列
回答by Othi
In your command, you have
在你的命令中,你有
grep "^ "
which filters out lines that do not start with a space.
它过滤掉不以空格开头的行。
With this, you're filtering out processes that have PIDs longer than 4 characters, since the top
command left pads the PIDs to 5 characters.
有了这个,您将过滤掉 PID 超过 4 个字符的进程,因为top
命令 left 将 PID 填充为 5 个字符。
Use grep "^[0-9 ]"
instead.
使用grep "^[0-9 ]"
来代替。
回答by S. Friese
Try top with the -u flag: top -u
使用 -u 标志尝试 top: top -u