将顶部数据导出到文件

发布于 2025-02-03 21:11:01 字数 257 浏览 3 评论 0原文

因此,我一直在尝试运行以下命令,以通过Firefox过程检查消费。

顶部-b | Grep“ Firefox”

现在我可以看到终端中所需的输出。但是现在,当我尝试将其导出到文件时,我无法。 我正在运行的命令是:

top -b | grep“ firefox”>>文件名top -B | grep“ firefox”>文件名

请提供帮助。

So I've been trying to run the following command to check the consumption by the firefox process.

top -b | grep "firefox"

Now I can see the desired output in terminal for it. But now when I try to export it to a file, I'm not able to.
The command I'm running is:

top -b | grep "firefox" >> filename or top -b | grep "firefox" > filename

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伏妖词 2025-02-10 21:11:01

您需要-n parm 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

You need the -n parm for top. For example,

top -b -n 1 | grep "firefox" >> firefox.out

Without -n 1 top will keep processing and will never make it to grep..
From the man page for top:

   -n  :Number-of-iterations limit as:  -n number
        Specifies  the  maximum  number of iterations, or frames, top
        should produce before ending.

Updated code with a while loop. It will loop forever unless you use
something like cntr variable. Remove the cntr code if you want
continuous monitoring:

#!/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
对你的占有欲 2025-02-10 21:11:01

您必须添加命令flag -n
更改要显示的过程数量。将提示您输入该号码。

要在Top Utility中使用特定过程的快照,请使用PID(-P)标志执行命令。

我也建议您要拍摄该过程的快照(PID),并获取PID的三个快照:
顶部-p 678 -b -n3>监视

You have to add in the command the flag -n
Change the number of processes to show. You will be prompted to enter the number.

To take a snapshot of a specific process in top utility, execute command with the PID (-p) flag.

Also i recommed if you want to take snapshots for the process one (PID), and get taking three snapshots of the PID:
top -p 678 -b -n3 > monitoring.out

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文