Skip to content

Instantly share code, notes, and snippets.

@morsik
Created February 22, 2012 17:05
Show Gist options
  • Save morsik/1886095 to your computer and use it in GitHub Desktop.
Save morsik/1886095 to your computer and use it in GitHub Desktop.
Calculates RAM usage by some program
#!/bin/bash
# Author: Konrad (morsik) Mosoń
# Usage: ./calcram.sh chromium
SUM=0
OUT=`ps aux | grep $1 | awk '{print $4}'`
for n in $OUT
do
SUM=`echo "$SUM + $n" | bc`
done
ALLRAM=`cat /proc/meminfo | grep MemTotal: | awk '{print $2}'`
USEDRAM=`echo "(($SUM) * ($ALLRAM / 1024)) / 100" | bc`
echo "$USEDRAM" M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment