views:

43

answers:

3

If you call the top command, you get all the running processes. But how can I limit the output only to a certain process name like "java"?

I've tried this top -l 2 | grep java but in this way you get only snapshots and not a continuously updated list. And top -l 0 | grep java is not really clear.

A: 

how about top -b | grep java

Faisal Feroz
Doesn't work on Mac because Mac uses BSD tools and not GPL tools. And there are some differences. I suppose the "-b" version is similar to "-l 0" but also the header of the table is printed?
Alexander Orlov
+1  A: 

Use the watch command

watch -d 'top -n1 | grep mysql'
tszming
Should be "watch --d". However I get no output executing this command.
Alexander Orlov
+1  A: 

Find the pids of the processes you want to monitor and then use the -p option which allows you to provide a list of pids to the top command.

Example:

top -p 18884 -p 18892 -p 18919

  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
18884 user  25   0  672M  95M  9476 S     0.0  1.1   0:02   1 java
18892 user  25   0 2280M 123M 12252 S     0.0  1.5   0:05   1 java
18919 user  22   0 1492M 198M 28708 S     0.0  2.4   0:07   1 java

(I believe you can also pass in a comma-separated list.)

dogbane
On Mac it should be "top -pid ID" but the Java process may have several distinct IDs as there may be several java processes.
Alexander Orlov