Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
> correctly measure available memory in linux
post Mar 27 2015, 02:15 AM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 8
Joined: 27-March 15
Member No.: 18,860

I'm currently using the command(s) below, to output the memory usage of a debian system in bash scripts.

memusage=$(memusage=$(/usr/bin/free | grep Mem | awk '{print $3/$2 * 100.0 "%"}' | cut -d "%" -f1);echo "$(printf "%0.0f\n" $memusage)") && echo Memory Usage is $memusage

Being new to Linux though, I just found out that Linux takes up a lof of memory and puts it in cached.

root@Client1:~# free -m
             total       used       free     shared    buffers     cached
Mem:           927        799        128          0         15        754
-/+ buffers/cache:         28        898
Swap:           99          0         99

So the first command will actually output that the memory usage is 87%, when in reality is not. Its actually thinking that the memory usage is high because its also counting the cached memory, as used memory.

How can I modify the first command not to consider cached memory, as used memory?
Go to the top of the page
+Quote Post
Start new topic
post Mar 27 2015, 05:42 AM
Post #2

Its GNU/

Group: Support Specialist
Posts: 1,807
Joined: 23-January 03
Member No.: 360

Free RAM in your case is the 898

root@Client1:~# free -m
total used free shared buffers cached
Mem: 927 799 128 0 15 754
-/+ buffers/cache: 28 898 <----
Swap: 99 0 99

So the percentage is (898/927)*100
Go to the top of the page
+Quote Post

Posts in this topic

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 16th July 2018 - 11:31 AM