I'm looking for somthing like top is to CPU usage. Is there a command line argument for top that does this? Currently, my memory is so full that even 'man top' fails with out of memory :]
asked Dec 19, 2010 at 6:41
2
From inside top
you can try the following:
- Press SHIFT+f
- Press the Letter corresponding to %MEM
- Press ENTER
You might also try:
$ ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5
This will give the top 5 processes by memory usage.
answered Dec 19, 2010 at 6:54
Steven DSteven D
43.7k13 gold badges112 silver badges112 bronze badges
5
If you have it installed I like htop
once launching it you can press f6, down arrow [to MEM%
], enter to sort by memory.
answered Dec 19, 2010 at 10:17
xenoterracidexenoterracide
55.6k70 gold badges180 silver badges244 bronze badges
In Solaris the command you would need is:
prstat -a -s size
This will list all processes in order of descending process image size. Note that the latter is based on memory committed to the process by the OS, not its resident physical memory usage.
There are supposedly versions of "top" available for Solaris, but these are not part of the standard installation.
answered Dec 19, 2010 at 13:42
1
Once top
starts,
press F to switch to the sort field screen. Choose one of the fields listed by pressing the key listed on the left; you probably want N for MEM%
answered Dec 19, 2010 at 6:53
Michael MrozekMichael Mrozek
88.1k34 gold badges235 silver badges230 bronze badges
2
This command will identify the top memory consuming processes:
ps -A --sort -rss -o pid,pmem:40,cmd:500 | head -n 6 | tr -s " " ";z"
Ouki
5,5844 gold badges22 silver badges31 bronze badges
answered Nov 4, 2014 at 6:26
user90191user90191
691 silver badge1 bronze badge
1
One nice alternative to top
is htop
. Check it, it is much more user friendly than regular top.
answered Dec 19, 2010 at 15:15
KlarkKlark
7666 silver badges4 bronze badges
Globally: It's always recommended to use a log analyser tool for logging history logs such as Splunk, ELK etc. So that using query language you can easily get the PIDs and its usage by CPU & memory.
AT SERVER/OS LEVEL: From inside top you can try the following:
Press SHIFT+M ---> This will give you a process which takes more memory in descending order.
You might also try:
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10
This will give the top 10 processes by memory usage. Also you can use vmstat utility to find the RAM usage at same time not for history.
answered Mar 2, 2020 at 11:10
1
It can be achieved in multiple ways, My favourite one is:
The PS way:
[arif@arif ~]$ ps -eo pid,cmd,%cpu,%mem --sort=-%mem
Where,
-e
: to select all process-o
: to apply to the output formatpid
,cmd
,%cpu
,%mem
: Output format in exact order. Here,pcpu
andpmem
can be used instead of%cpu
and%mem
.- But sadly [don't know why] it doesn't work on some machine [Oracle Linux] and some older machine. You can use the following similar alternatives.
[arif@arif ~]$ ps aux --sort '-%mem' --cols 120 | head
Where,
--cols 100
: to specify column width of the output as sometimescmd
gets very long. This is not necessary if you don't want curtailed commands with arguments.aux
: to see every process on the system using BSD syntax
[arif@arif ~]$ ps -eo pid,cmd,%cpu,%mem --sort -rss
Where,
-rss
: resident set size, the non-swapped physical memory that a task has used
[arif@arif ~]$ ps aux --sort -rss --cols 120
The top way:
[arif@arif ~]$ top -b -o +%MEM
Where,
-b
: to usetop
asbatch
mode.-o
: to override sort fieldname followed by a fieldname%MEM
And you can always use head
and/or tail
to control the output.
answered Jan 5, 2020 at 0:16
arifarif
1,3093 gold badges14 silver badges27 bronze badges
1
You can try ps aux --sort -rss | head
or ps aux | sort -nk +4 | tail
answered Jul 14, 2017 at 14:40
David OkwiiDavid Okwii
4051 gold badge4 silver badges7 bronze badges
1
This alias works nice for me in a bash shell:
alias mtop='{ echo "Mem% PID Binary"; ps -A --sort -rss -o pid,pmem:40,cmd:500 | tail -n +2 | head -n 10 | tr -s " " | sed -r "s/^\s*[[0-9]+] [[0-9.]+] [[a-zA-Z/]+].*$/\2 \1 \3/"; } | column -t -s " "'
This will print out a neat list of processes sorted by memory consumption:
-=# mtop
Mem% PID Binary
22.9 528235 /opt/intellij
5.4 906569 /usr/share/elasticsearch/jdk/bin/java
3.7 544512 /usr/bin/node
2.2 986170 /usr/lib/firefox/firefox
1.9 795138 /usr/bin/node
1.1 795188 /usr/bin/node
1.0 747819 /usr/lib/jvm/java
0.9 599 /usr/bin/pipewire
0.7 414 /usr/lib/Xorg
0.7 544536 /usr/bin/node
answered Jul 9 at 10:29
fassegfasseg
1013 bronze badges