Are there any relatively strightforward options with top to track a specific process?
Ideally by identifying the process by a human readable value? e.g. chrome or java.

In other words, I want to view all the typical information top provides, but for the results to be filtered to the parameters provided i.e.. 'chrome' or 'java'

  • 1
    have you tried top | grep chrome? – Pandya Oct 31 '14 at 10:59
  • 1
    you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034 – Pandya Oct 31 '14 at 11:02
  • top | grep chrome worked perfectly - thanks! – Michael Coleman Oct 31 '14 at 11:05
  • @Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it. – Michael Coleman Oct 31 '14 at 11:15

You can simply use grep:

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

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

       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.

  • 1
    thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation... – Michael Coleman Nov 1 '14 at 16:11
  • 3
    This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one – j b Aug 11 '17 at 12:18
  • @JamieBullock the question deals with top only and OP want to filter process based on top. – Pandya Aug 11 '17 at 13:26
  • @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep – j b Aug 11 '17 at 13:41
  • I like unix.stackexchange.com/a/165343/48973 better because it shows the headers. – Ryan Jul 14 '18 at 17:12

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

top -p `pgrep "java"`
  • 4
    top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top? – Michael Coleman Nov 1 '14 at 8:33
  • @Ramesh you need to give the pid list comma separated to work. – Kannan Mohan Nov 1 '14 at 13:33
  • 3
    This is the right answer. – j03m Aug 8 '16 at 13:51
  • 1
    +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy. – John M Naglick Jan 25 '17 at 16:36
  • 2
    @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes. – Michael Hays Nov 25 '18 at 15:28
top -p `pgrep -d "," java`


  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.

  • 1
    This solution works better than using top -p pgrep "java"`` only. thank you. – loretoparisi Sep 24 '18 at 8:26
  • 1
    Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids" – syme Nov 30 '18 at 16:42
  • This solution does not "update" because pgrep is only evaluated once. See @Kusalananda's answer which uses top filtering. – linux_pangolin Nov 27 at 1:14

In OpenBSD top, just press g and enter the command name you'd like to filter on.

In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are equal to chrome.

On Linuxes that uses the same top implementation as Ubuntu, read the FILTERING in a Window section in the top manual.

  • This answer has the benefit of updating if a new process begins after calling top! – linux_pangolin Nov 27 at 1:12

Other good answers have been provided, but I made a script some time ago, which I named ptop, that serves me well:

top -p $(pidof "$@" |sed s#\ #,#g) 2>/dev/null
if [ $? -ne 0 ]; then
  echo No processes with the specified name\(s\) were found

This supports multiple process names to be specified (like ptop bash chrome) and provides a nicer error message in case there is/are no processes with any of the specified names running.


If you want to stay in top and keep all other processes in view for context, you can press L to search for your process:

Locate string chrome

This will highlight any process with chrome in the name, and bring it into view. Use & to go to the next match.

You can press c to switch between showing the process name and the full command.

  • This ^ because RTFM people! man top | less +/5d – cprn Oct 26 '18 at 14:09

You can also use a filter in top to isolate specific processes. Press 'O' to bring up the filter prompt. Then type a filter formatted as FIELD=value. For example, to filter all tmux processes, use:


Use '=' to reset filters. See the section titled 'FILTERING' in the top man page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.