shell script to find linux memory process usage


The following script will check for top 20 processes which uses maximum memory resource in the server and will store it in “overusage” file only if the free memory goes below 700MB. Set cron to execute this script whenever needed.



#High RAM usage checker
r=`free -m |awk 'NR==3' |awk '{ print$4 }'`
if [ $r -lt 700 ];
ps -e -orss=,args= | sort -b -k1,1n |tail -n 20 >> overusage


  1. Antenore says:


    This script will check the free memory without taking into account the cached and buffered memories

    For example

    free -m
    total used free shared buffers cached
    Mem: 3894 3719 174 0 121 1965
    -/+ buffers/cache: 1632 2262
    Swap: 8191 0 8191

    This machine has around 2GB of free memory, even if the free column show just 174.

    • Siru says:

      You are right, I would possibly write another script to take cache and buffered RAM into account for calculation.

Leave a Reply

Protected by WP Anti Spam