如何使用 top 只显示 CMD 名称

如何使用 top 只显示 CMD 名称

top只显示 CMD 名称如何使用?

我已经使用了top仅显示我想要的正在运行的进程;例如:

$ top -p 19745

如果我想要多个 PID,我会使用:

$ top -p 19745 -p 19746 -p 19747

我已经用谷歌搜索过它,但他们没有说你如何做到这一点,即使我尝试查看其中的帮助top仍然没有告诉你。

有没有一种方法可以仅按 CMD 名称进行过滤?

我正在通过 Apache2 运行某些文件,并且我只想监视它们。

afile1.abc
afile2.abc
afile3.abc
afile4.abc

更新

我在页面中看到这个man top

x: Command  --  Command line or Program name
      Display the command line used to start a task or the name of the associated
      program.   You toggle between command line and name with 'c', which is both
      a command-line option and an interactive command.

      When you've chosen to display command lines, processes  without  a  command
      line  (like  kernel  threads)  will  be shown with only the program name in
      parentheses, as in this example:
            ( mdrecoveryd )

      Either form of display is subject to potential truncation if it's too  long
      to fit in this field's current width.  That width depends upon other fields
      selected, their order and the current screen width.

      Note: The 'Command' field/column is unique, in that it is not  fixed-width.
      When  displayed,  this  column will be allocated all remaining screen width
      (up to the maximum 512 characters) to provide for the potential  growth  of
      program names into command lines.

这对我有什么作用吗?

答案1

如果您top支持过滤,请启动top然后键入以下交互式命令:

oCOMMAND=afile

字段名称COMMAND必须全部大写。

从手册页:

5e. FILTERING in a Window
   You can use the 'Other Filter' feature to establish selection cri‐
   teria which will then determine which tasks are shown in the ´cur‐
   rent´ window.

   Establishing a filter requires: 1) a field name; 2)  an  operator;
   and  3) a selection value, as a minimum.

   Filter Basics
      .  field names are case sensitive and spelled as in the header
      .  selection values need not comprise the full displayed field
      .  separate unique filters are maintained for each task window

Keyboard Summary
     o  :Other-Filter (lower case)
         You will be prompted to establish a filter that ignores case
         when matching.

     O  :Other-Filter (upper case)
         You will be prompted to establish a case sensitive filter.

答案2

我相信你可以按照建议做类似下面的事情这里

top -p `pgrep -d ',' "apache2"`

我相信在这种情况下不需要逗号分隔符,因为我们只有一个进程。

top -p `pgrep "apache2"`

相关内容