How to view a specific process in top

From my other answer here, you could do something like,

top -p `pgrep "java"`

You can simply use grep:

NAME
       grep, egrep, fgrep, rgrep - print lines matching a pattern

SYNOPSIS
       grep [OPTIONS] PATTERN [FILE...]
       grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
       grep  searches  the  named  input  FILEs (or standard input if no files are named, or if a single
       hyphen-minus (-) is given as file name) for lines containing a match to the  given  PATTERN.   By
       default, grep prints the matching lines.

Run following command to get output which you want (ex-chrome):

top | grep chrome

Here we are using grep with pipelines | so top & grep run parallel ; top output given to grep (as input) and grep chrome filters matching lines chrome until top stopped.


top -p `pgrep -d "," java`

Explanation:

  1. top -p pid1,pid2: show multiple process information, the pid should be separated by ,
  2. pgrep -d "," java: print the pids of all java program, the pids are separated by a newline by default. use the -d "," to separate it by , as required by the top.

If you see error like top: -p argument missing, it means no java program is running, i.e. the pgrep has no output.

Tags:

Process

Top