How to check memory usage in linux

The are actually multiple way to do this… lets start with the easiest

# -m makes it give result i MB, default is KB
free -m

#for a continuous feed
watch free -m

Result:

root@devget:/etc/nginx/sites-available# free -m
             total       used       free     shared    buffers     cached
Mem:          1024        225        798          0          0          0
-/+ buffers/cache:        225        798
Swap:            0          0          0

 Next up is my personal fav

# Note: press q to quit
top   // also try 'htop' or 'atop'

Result:

top - 17:40:47 up 16 days, 18:44,  1 user,  load average: 3.75, 3.79, 3.78
Tasks:  26 total,   1 running,  25 sleeping,   0 stopped,   0 zombie
%Cpu(s): 21.6 us, 24.3 sy,  0.0 ni, 53.4 id,  0.1 wa,  0.0 hi,  0.7 si,  0.0 st
KiB Mem:   1048576 total,   326920 used,   721656 free,      668 buffers
KiB Swap:        0 total,        0 used,        0 free,        0 cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND                                  
 6014 root      20   0 21584 1444 1080 R     0  0.1   0:00.01 top                                      
13045 root      20   0  109m 5516 1264 S     0  0.5   0:18.80 rsyslogd                                 
  874 root      20   0 71160 3676 2868 S     0  0.4   0:00.26 sshd                                     
 1253 root      20   0 17848 2064 1540 S     0  0.2   0:00.02 bash                                     
 5197 root      20   0 76356 1536  332 S     0  0.1   0:00.00 nginx                                              
 5202 www-data  20   0 77304 3148 1076 S     0  0.3   0:00.34 nginx                                    
 6029 root      20   0 14524  916  748 S     0  0.1   0:00.00 getty                                 
 9292 root      20   0 49624 8164 1500 S     0  0.8   0:01.61 python                                   
    1 root      20   0 10600  848  712 S     0  0.1   1:05.15 init                                     
13037 root      20   0  134m 5028 1404 S     0  0.5   0:33.66 php5-fpm                                 
13064 root      20   0 18828  960  732 S     0  0.1   1:26.80 cron                                     
13124 root      20   0  4128  744  604 S     0  0.1   0:00.01 mysqld_safe                              
13463 mysql     20   0  555m 122m 8320 S     0 12.0   2333:36 mysqld                                   
13464 root      20   0  4036  680  576 S     0  0.1   0:00.00 logger                                   
13475 root      20   0 49800 1252  644 S     0  0.1   0:00.04 sshd                              
30090 www-data  20   0  143m  17m 3896 S     0  1.7   0:09.78 php5-fpm

Some cool tips:

Sort top by CPU Usage: O > K > Enter
Sort top by Memory Usage: O > M > Enter

Lastly

# This one shows a buncha stuff so prepare for information overload
less /proc/meminfo # or cat /proc/meminfo

#to make things lss cryptic
egrep --color 'Mem|Swap|Cache' /proc/meminfo  
# or 
cat /proc/meminfo | grep -e Mem -e Swap -e Cache

Sidenote: ‘cat /proc/cpuinfo’ will show cpu info

You may also like...

Leave a Reply