Total Hit Counter

Thursday, November 1, 2012

How to check memory used by process




Shell Script to check Memory usage by Process  in linux


#!/bin/bash
#####
# To check memory used by particular process
#Created by Shankar Patel
#Create date : 1-11-2012
########################################################################
if [ "$1" = "" ] ; then  echo -e "Please Provide process name as a argument . \nExample: $0 java" ; exit 1;fi 
pidsof_procs=`pidof $1`
for i in $pidsof_procs
do
        mem[$i]="`cat /proc/$i/status | awk '/VmPeak/ {print $2}'`"
        #cat /proc/$i/status | awk '/VmPeak/ {print $2}'
done
for i in $pidsof_procs
do
        echo -e "$i is using $((${mem[i]}/1024)) mb"
done
exit 0