将TOP命令的输出限制为特定的进程名称 [英] Limit the output of the TOP command to a specific process name
本文介绍了将TOP命令的输出限制为特定的进程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果调用top命令,您将获得所有正在运行的进程。但是我如何才能仅限限制某个进程的名称,例如java
If you call the top command, you get all the running processes. But how can I limit the output only to a certain process name like "java"?
试过这个
top -l 2 | grep java
,但这样您只能获取快照,而不是持续更新的列表。和 top -l 0 | grep java 不是很清楚。
I've tried this top -l 2 | grep java but in this way you get only snapshots and not a continuously updated list. And top -l 0 | grep java is not really clear.
推荐答案
我更喜欢以下所以我仍然可以使用交互式顶部,每次我运行它查找pids:
I prefer the following so I can still use top interactively without having to look up the pids each time I run it:
top -p `pgrep process-name | tr "\\n" "," | sed 's/,$//'`
当然,如果进程改变,重新运行命令。
Of course if the processes change you'll have to re-run the command.
说明:
-
pgrep process-name
返回由换行符分隔的进程ID列表 -
tr\\\\
将这些换行符转换为逗号,因为top想要一个以逗号分隔的进程ID列表
-
sed
是流编辑器,sed's /,$ //'
用于删除结尾的逗号
pgrep process-name
returns a list of process ids which are separated by newlinestr "\\n" ","
translates these newlines into commas, because top wants a comma-separated list of process idssed
is a stream editor, andsed 's/,$//'
is used here to remove the trailing comma
这篇关于将TOP命令的输出限制为特定的进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文