Bash Script: MemUse

Quick useful function to get all of the memory in use by a process or set of processes from a bash prompt:

memuse() {
  arr=`ps aux | grep -E $1 | grep -v grep | sed -e 's/[^ \t]*[ \t]*[^ \t]*[ \t]*[^ \t]*[ \t]*//' | sed -e 's/[ \t].*//'`
  sum=0
  for i in $arr
    do
      sum=$(echo "$sum + $i" | bc)
    done
  echo $sum
}
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.