Linux check memory usage

by Vivek Gite · 19 comments

Linux comes with different command to check memory usage. free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.

vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity.

Then you can use top command which provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

free command

Display free memory size in MB:

$ free -mOutput:

             total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        254        496
Swap:          956          0        956

Displays a line containing the totals memory in MB:
$ free -t -m
Output:

       total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        253        496
Swap:          956          0        956
Total:        1707        625       1082

vmstat command

Type vmstat command at shell prompt:
$ vmstatOutput:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
1  0      0 131620  35432 341496    0    0    42    82  737  1364 15  3 81  1

top command

Type top command at shell prompt:
$ topTo exit from top command type q key.

Read man page of free, vmstat, top command for complete information.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 19 comments… read them below or add one }

1 suresh 09.12.07 at 8:12 am

Hi ,

I need a unix command to get the total memory usage percentage.so that i can call this command from java.The output of the command should only be the percentage of memory utilization.

thanks
Suresh

2 Matt 11.30.07 at 4:01 pm

Try:

ps aux | awk ‘{sum +=$4}; END {print sum}’

Bye!

3 Michael 12.06.07 at 4:00 pm

Using the command free, vmstat, top all shows it uses almost 100% of the memory. But if I use the system monitor, it will show only less than 10%.

I am using CentOS 5. can anyone explain why the free, vmstat, top all displaying wrong information? Thanks.

$ free -m
total used free shared buffers cached
Mem: 3792 3638 154 0 128 3231
-/+ buffers/cache: 277 3515
Swap: 1983 0 1983
$ vmstat
procs ———–memory———- —swap– —–io—- –system– —–cpu——
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 108 158380 131948 3309388 0 0 106 75 203 180 0 0 98 1 0

4 Atahan 02.01.08 at 7:30 am

Actualy memory is not used by application, but it is used for disk caching.
If memory is not fully utilized by kernel than it is wasted, by keeping data in cache when an application needs data again it can be provided faster.
If you want to see the memory from the perspective of application you should look at +- buffers/cache line, the free column of this line shows you the memory that can be used for applications.

In the case below my application using 2GB of memory.

# free -m
total used free shared buffers cached
Mem: 7973 7323 650 0 128 5152
-/+ buffers/cache: 2042 5931
Swap: 8189 40 8149

5 Ohm 05.20.08 at 4:15 am

Hi ,

I take care 2000 PCs that using Redhat 7.3. I’m finding the command to create script file to check RAMBus of the PCs. Could you please help to recommend the appropriate one ?

Thanks.

Regard,

6 pudhiyavan 06.19.08 at 6:49 pm

is there any way/script to find out physcial memory usage exclusive of buffer/cache usage??

7 don 08.06.08 at 9:28 am

very good
thanks
Regard,

8 Shaukat Ali Gill 11.09.08 at 1:58 pm

You can also check memroy by using command “cat /proc/meminfo” it will give you detail info.

9 Duncan 12.05.08 at 8:23 pm

the memory information is also stored in /proc/meminfo… so just in case you don’t have any tools installed… cat /proc/meminfo

10 amm 01.10.09 at 1:03 pm

hi all

I use sun servers and solaris os and memory load has been increased to 90%

I need to know which command can i use to check on its memory and how i know the abnormal increase

11 kshard 01.22.09 at 1:06 pm

hi all

I am trying to get the output of the command top in java using a processbuilder. But its not giving any output. Though a command such as ‘ps -all’ is giving the required output. Can anyone help please. Its urgent…

Thanks

12 team fortress 01.23.09 at 10:05 pm

How can I find the memory used by each php script on the server?

13 kishore 02.21.09 at 10:55 am

hi this is kishore

with single command can we get information of version of linux , ram,and memory status informationa. And as well as with single command the total system information
can i know the comman of linux

Regards
kishore

14 Oink! 03.30.09 at 7:51 am

[kishore] You need to write a script which excutes various commands and output as a single command.

15 Psycho Tux 04.30.09 at 9:01 am

ps aux | awk ‘{sum +=$4}; END {print sum}’. It works.
Thanks Matt…
Is there any way to do the same for SWAP also.

16 Ajay Kumar Bysani 06.15.09 at 6:36 am

How can get the average memory usage of a perl script that I am running on a linux machine? Can anybody help?

17 T Sudhakarraj 08.13.09 at 4:22 am

Hi kishore

Use this coomand to get all the required information

lsb_release -a && free -m

18 Paul Plowman 09.03.09 at 4:54 pm

Believe that we have a memory leak on RHEL 4.5 with Java & Apache running.

ps -eo pid,ppid,rss,size,vsize,sz,pmem,comm | awk '{ rss += $3; size += $4; vsize += $5; sz += $6; pmem += $7} ; END { print "rss = "rss" size = "size" vsize = "vsize" sz = "sz" pmem = "pmem }' ; free -m
rss = 4590060 size = 7302928 vsize = 11360544 pmem = 26.7
total used free shared buffers cached
Mem: 16028 15979 48 0 0 24
-/+ buffers/cache: 15954 73
Swap: 32767 4571 28196

Does anyone have a command, code, or program to identify where the memory is being utilized?
After a reboot the server is using 24.6% of memory or free shows 4869 MiB.

Thanks.

19 T Sudhakarraj 09.04.09 at 7:13 am

Hi Paul,

ps -auxf | sort -nr -k 4 | head -10

The above mentioned command will display top 10 memory usage in % by each process

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All