linux - 如何从 linux 中的文件中获取 pids 列表?

标签 linux bash shell pid

我有一个脚本来获取 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/

相关文章:

linux - 无法弄清楚如何编译 Linux 内核模块

c - Linux waitid 中__WALL 的使用

linux - GUI 工具包如何与 Linux 上的窗口管理器通信?

bash - 将变量添加到 awk 命令

bash - 通过 bash 从文件中检索电子邮件主题

bash - 在 Cygwin 上加速文件比较(与 `cmp` )?

linux - 在 Linux 的 Shell 脚本中复制 SCP 命令?

c - 信号量无破坏/取消竞争条件

unix - 比较两个内容有很多文件的文件夹

linux - '2>&1' 和 '&>filename' 之间的区别