Skip to content

Instantly share code, notes, and snippets.

@milushov
Created May 17, 2013 17:34
Show Gist options
  • Save milushov/5600639 to your computer and use it in GitHub Desktop.
Save milushov/5600639 to your computer and use it in GitHub Desktop.
# Show how much RAM application uses.
# $ ram safari
# # => safari uses 154.69 MBs of RAM.
function ram() {
local sum
local items
local app="$1"
if [ -z "$app" ]; then
echo "First argument - pattern to grep from processes"
else
sum=0
for i in `ps aux | grep -i "$app" | grep -v "grep" | awk '{print $6}'`; do
sum=$(($i + $sum))
done
sum=$(echo "scale=2; $sum / 1024.0" | bc)
if [[ $sum != "0" ]]; then
echo "${fg[blue]}${app}${reset_color} uses ${fg[green]}${sum}${reset_color} MBs of RAM."
else
echo "There are no processes with pattern '${fg[blue]}${app}${reset_color}' are running."
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment