这是 top 命令的输出:
Mem: 245108K used, 784400K free, 6636K shrd, 15128K buff, 41824K cached
CPU: 12% usr 0% sys 0% nic 87% idle 0% io 0% irq 0% sirq
Load average: 2.62 2.58 2.57 2/90 29509
我需要一个单行脚本命令来执行并获取“CPU”行。
我可以从“cat/proc/meminfo”获取Mem行,并从“cat/proc/loadavg”获取平均负载。
有什么方法可以让 CPU 达到相同的效果吗?
最佳答案
@md.jamal -- 尝试此操作,获取当前使用资源最多的 10 个进程 ID(包含 %CPU 和 %MEM)。
ps -eo pid,ppid,%cpu,%mem | sort -rnk3 | head
Below is details for above command:
where ps --> reports snapshot of current process
-e --> select all processes
-o --> output format
sort -r --> reverse sort, ie descending order
sort -n --> numeric sort
sort -k3 --> to select column no:3
head --> to display top 10 records
关于linux - shell 脚本中 top 命令的 CPU 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48533978/