gpt4 book ai didi

linux - 将顶级数据导出到文件

转载 作者:行者123 更新时间:2023-12-04 19:31:04 25 4
gpt4 key购买 nike

所以我一直在尝试运行以下命令来检查firefox进程的消耗。top -b | grep "firefox"现在我可以在终端中看到所需的输出。但是现在当我尝试将其导出到文件时,我无法做到。
我正在运行的命令是:top -b | grep "firefox" >> filenametop -b | grep "firefox" > filename请帮忙。

最佳答案

您需要 -n top 的参数.例如,

top -b -n 1 | grep "firefox" >> firefox.out
没有 -n 1 top将继续处理,永远不会到达 grep ..
来自 top 的手册页:
   -n  :Number-of-iterations limit as:  -n number
Specifies the maximum number of iterations, or frames, top
should produce before ending.
使用 while 更新了代码环形。除非您使用,否则它将永远循环
类似于 cntr多变的。删除 cntr如果你想要代码
持续监控:
#!/bin/sh
#
not_done=1
cntr=0
# Look for process firefox every 1 seconds
while [ "$not_done" -eq 1 ]
do
top -b -n 1 | grep "firefox" >> /tmp/firefox.out
sleep 1
((cntr=cntr+1))
# Addition logic to break out of loop after 10 iterations
if [ "$cntr" -eq 10 ]
then
not_done=0
fi
echo "cntr=$cntr"
done

关于linux - 将顶级数据导出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72472573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com