2

How do you use top with just showing the CMD name?

I have used top with just showing the running process that I want; for example:

$ top -p 19745

And if I want more than one PID, I would use:

$ top -p 19745 -p 19746 -p 19747

I have Googled it, but they don't say how you can do it, even when I try looking at the help in top it still doesn't show you.

Is there a way you can filter by the CMD name only?

There are certain files that I am running through Apache2, and I want to monitor them only.

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

Update

I see this in the man top page:

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.

Will that do anything for me?

0

2 Answers 2

3

If your top supports filtering, start top then type the following interactive command:

oCOMMAND=afile

The field name, COMMAND, must be all uppercase.

From the man page:

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.
4
  • Should I use this command line: top oCOMMAND=afile? I tried that and got: top: unknown argument 'o' Commented Jul 30, 2014 at 15:36
  • 1
    The o command is an interactive command only, as far as I can tell. Start top first, then type it. Commented Jul 30, 2014 at 15:37
  • Oops, I moved the X: COMMAND to the top of the filters list. It is now in the front of the list. But I can't filter it by only that one filename: afile Commented Jul 30, 2014 at 15:42
  • I have used top -i and have all the running processes, which is sufficient for me, as I have this machine on VirtualBox. Commented Jul 30, 2014 at 15:56
3

I believe you could do something like below as suggested here.

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

I believe the comma delimiter is not needed in this case as we have only one process.

top -p `pgrep "apache2"`
10
  • Sorry, I edited my post, saying: "There is a certain file that I am running through Apache2, and I want to monitor it only." - I can sort them alphabetically by pressing c, but that doesn't really help... Well it does for me, as the filename starts with "A" Commented Jul 30, 2014 at 14:41
  • @Kevdog777, please see the updates. Commented Jul 30, 2014 at 14:42
  • Oh wait, it disappears when it refreshes itself. Commented Jul 30, 2014 at 14:45
  • @Kevdog777, I believe the comma delimiter is not needed in pgrep. Can you try the updated command? Commented Jul 30, 2014 at 14:56
  • I am getting this: top: unknown argument '1' Commented Jul 30, 2014 at 14:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.