In order to check memory usage in Linux , there are several commands , but the most useful commands I have found are the following :
Check total memory usage :
# free -m total used free shared buffers cached Mem: 512 490 21 0 16 160 -/+ buffers/cache: 314 197 Swap: 1023 76 947
what you are looking for is in front of “-/+ buffers/cache:” , in above example Total memory is 512MB , Used memory is 314MB and Free memory is 197MB.
it also shows the usage of Swap which is 76MB from 1023MB Total.
Check detailed processes memory usage :
# ps aux | awk '{print $4"\t"$11}' | sort | uniq -c | awk '{print $2" "$1" "$3}' | sort -nr 10.0 1 (squid) 2.7 1 python 1.5 1 /usr/sbin/pdns_recursor 1.3 1 sshd: 1.3 1 /usr/sbin/apache2 .........
This command is a little complex , we dont want to go into the details of command. we are only interested in the output.
The First column shows the percent of memory which this process is using , second column shows the number of instances of the process and the third column is the name of process. in the above example , process “squid” is using 10% of my server memory and python is using 2.7% of memory.