I want top command to show processes that are greater than PID xxx is there a switch that can do that? also can I sort the output based on the PID number instead of the CPU usage?
3 Answers
By default top
runs every 3s.
You can monitor processes greater than PID XXX by using the watch
command and top
in batch mode (with -b
, for 1 iteration with -n 1
and sorted by PID with -o PID
):
watch -n 3 "top -o PID -b -n 1 | perl -ne '/^\s+(\d+)\s+/; print if (not \$1 or \$1 > 5000)'"
Where for example 5000 is my threshold:
Tested on 14.04
You can run top -o PID
to sort by PID (or hit the <
key several times while top is running to move the sort column to the right, until it's sorting by PID).
You can filter PIDs interactively while top is running by hitting the o
key and typing PID>1000
or whatever minimum value you want, followed by enter.
-
2
-
@Hinklo This works, and this is the way you would do it. Instead of looking for "some other way", I'd investigate why it doesn't work for you. What exactly happened (i.e, what does "it didn't work" mean)? Are you referring to the sorting, or the filtering? or did neither work? You may have done something wrong. Did you try the
PID>1000
filter as suggested by Stephen for a start? You can also see a list of active filters by hitting Ctrl+o. Do you see thePID>1000
one? Pay attention to upper-/lowercase:pid>1000
will not work. Sep 9, 2014 at 8:29 -
-
-
3I can confirm the filter does not work on Ubuntu 14.04. And no, it is not clear why, it functions with other fields. Sep 9, 2014 at 18:29
h
to see the various options yourtop
supports.top -v
anddpkg -S $(which top)
to your post? I suspect you may be using some unusual implementation. The normal way to solve your problem should work, as can be seen in this video: youtube.com/watch?v=tE1le-9lALc.