linux - 所有 pid 的 CPU 使用率

标签 linux bash shell cpu-usage pid

在不知道任何程序名称的情况下,我无法获取所有 pid 的 CPU% 使用率。

我觉得我已经接近解决方案了,这就是我到目前为止所做的:

for line in $(pgrep -f chrome); \
   do echo -n $line" - ";       \ 
   ps -p $line -o %cpu | sed -n 2p | sed 's/ //'; done

在此示例中,我仅获取所有 chrome pid..在下一步中,我希望所有执行 pid。

最佳答案

您可以单独使用 top 命令轻松完成此操作。

要按 CPU 百分比(降序)排序,您可以使用 top -o -cpu

关于linux - 所有 pid 的 CPU 使用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22047863/

相关文章:

linux - 如何从远程 SSH session 将数据发送到本地剪贴板

bash - 如何在我的 git 提交消息中提交代码块

bash - 如何删除 bash 输出中的装饰颜色字符?

linux - 比较 shell 脚本和 delta 中的文件

linux - "grep -e"和 "grep -E"有什么区别

c++ - Linux 中的可执行文件会影响链接动态库中的浮点精度吗?

linux - 从公共(public) IP 访问网络服务器重定向到服务器的本地 IP 并失败(ubuntu apache2,moodle 托管)

linux - 在 netbeans 中部署 java 桌面应用程序

linux - 用于在 PI 模式之间切换的 BASH 脚本

linux - 请解释 Linux bash exec 和 ssh-agent 行为