想要看所有的包含某个字符的进程的 top 结果:
top -c -p $(ps aux|grep -i some_string|perl -ae 'print "$F[1],"'|perl -ne 's/,$//; print') # 可以运行 OK
ps aux|grep -i some_string|perl -ae 'print "$F[1],"'|perl -ne 's/,$//; print'|xargs -I {} top -c -p {} # 报错 top: failed tty get
而 top 的非交互界面却可以接收管道输入,并正常得到结果:
ps aux|grep -i some_string|perl -ae 'print "$F[1],"'|perl -ne 's/,$//; print'|xargs -I {} top -b -n 1 -c -p {} # 可以运行 OK
请各位彦祖帮忙看下为什么。谢谢
1
chengxiao 2022 年 6 月 22 日 via Android
装 htop
|
3
hsfzxjy 2022 年 6 月 22 日 交互式命令通常要求 stdout 是 tty ,但管道会让 stdout 失去 tty 这一属性。你需要的是 process substitution
xargs -I {} -a <(ps aux | grep -i some_string | perl -ae 'print"$F[1],"' | perl -ne 's/,$//; print') top -c -p {} |