I set an alarm on my cell phone that when ever RAM usage exceeds 90% then got an alert. I also made a script to monitor all the memory, CPU, RAM etc.

How can I reduce the RAM usage where I also have a script of clear cache... but I can't run it all the time or set a cron against it, because it affects the live service. Kindly suggest to me the way to resolve the RAM utilization

I have a following script:

memory_alarm=`/usr/bin/free -m|grep Mem|awk '{print $3/$2 * 100.0}'|cut -d\. -f1`

when I ran a top command, it shows 66% and after some seconds the alerts received of RAM usage 95%

  • So you want to automatically run your clear-cache script whenever the "used" value goes above, say, 90% of system memory? – Ulrich Schwarz Apr 25 '16 at 9:18
  • Cron is already set to 15 mints... – Nauman Shakil Apr 25 '16 at 9:33
up vote 1 down vote accepted

You are not taking the page cache into consideration (under the 'cache' column in free's output). Data written to disk will be held in the cache, and will be flushed when the file is removed/replaced, or free memory becomes low and other processes request more memory.

$ free
             total       used       free     shared    buffers     cached
Mem:       2038308    1890180     148128        504      25072     489884
-/+ buffers/cache:    1375224     663084
Swap:      8386556       7440    8379116
$ /usr/bin/free -m|grep Mem|awk '{print $3/$2 * 100.0}'|cut -d\. -f1
$ /usr/bin/free -m|grep Mem|awk '{print ($3-$7)/$2 * 100.0}'|cut -d\. -f1
  • awk can do most of this: free -m | awk '/Mem/ {print int(($3-$7)/$2*100)}' – dave_thompson_085 Apr 25 '16 at 13:09
  • Oh totally, I was just correcting the original process rather than attempting to optimise. – neuro Apr 25 '16 at 13:40

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.