Limit the top command to only display the top X processes on the command line
I am not sure why top
there is no option in the command that does this as it seems like a natural request.
If I pipe the output top
to head
, then the list is not updated and I get static output once. Then I could put a team watch
in motion to do the job. But is there an easier solution?
source to share
> top
then click n
to display the maximum objectives.
When working from above, one of the most important keys is to help ( h
or ?
) to see the available options ( n
given in the help).
UPDATE (after comment):
PERSONAL Configuration File
can help in batch. Run top
then set the maximum tasks displayed with n
and use the interactive command W
to create or update the config file. top
will be launched according to the config file next time.
source to share
I use a trick, especially for batch mode. I pipe out to grep with the "-A" option to show N lines after the match.
As with the first line of the top, there is something like: "load average", I grep, for example:
$ top -d 5 -b|grep "load average" -A 15
top - 09:42:34 up 38 min, 1 user, load average: 0.22, 0.39, 0.53
Tasks: 294 total, 2 running, 291 sleeping, 0 stopped, 1 zombie
%Cpu(s): 3.5 us, 0.9 sy, 0.0 ni, 94.6 id, 0.5 wa, 0.3 hi, 0.1 si, 0.0 st
KiB Mem : 8065144 total, 2213800 free, 2733524 used, 3117820 buff/cache
KiB Swap: 24575996 total, 24575996 free, 0 used. 4613128 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2744 lrojas 20 0 3376820 752000 116588 R 20.2 9.3 9:30.01 firefox
1869 lrojas 9 -11 566164 18336 14300 S 5.2 0.2 2:35.78 pulseaudio
2401 lrojas 20 0 740092 200456 87256 S 2.4 2.5 0:57.29 skype
2402 lrojas 20 0 617872 172924 76172 S 2.2 2.1 0:57.17 skype
1333 root 20 0 459028 60992 48024 S 1.6 0.8 0:36.14 Xorg
1838 lrojas 20 0 2103336 184468 64724 S 1.4 2.3 0:56.85 gnome-shell
2359 lrojas 20 0 741212 35068 24620 S 1.4 0.4 0:06.83 gnome-terminal-
2404 lrojas 20 0 1867556 229912 83988 S 0.8 2.9 0:19.63 thunderbird
1249 apache 20 0 461436 10196 3404 S 0.4 0.1 0:00.57 httpd
So it will continue in batch mode, always displaying only the first N lines of output.
Completely standard solution for any version of top.
source to share