我有一个脚本来获取 pid 的列表 我想查看那些使用 top 的 pids 的 cpu 使用情况和内存使用情况。
我可以在 pid 列表中排在最前面:
top -p pid1,pid2,pid3
我有一个返回我需要的 pid 的函数,我正在将其转换为逗号分隔列表,如下所示:
$ gal vppoc|cut -d" " -f1|xargs|sed -e 's/ /,/g'
12775,13319,14404,14549,14920,27534
但是,以下内容不起作用:
gal vppoc|cut -d" " -f1|xargs|sed -e 's/ /,/g'| top -p
它给出了错误:
top: -p argument missing
需要一些帮助才能使其正常工作 - 即能够覆盖我上面的函数返回的 pid。
谢谢
最佳答案
您正在使用 |
(管道),它将一个进程的标准输出连接到另一个进程的标准输入。
你需要的是
top -p $(your_function_here)
例如
top -p $(gal vppoc|cut -d" " -f1|xargs|sed -e 's/ /,/g')
关于linux - 如何从 linux 中的文件中获取 pids 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693578/