Skip to content

Instantly share code, notes, and snippets.

@thegitfather
Last active January 24, 2016 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegitfather/35e5a3df330eddf565f2 to your computer and use it in GitHub Desktop.
Save thegitfather/35e5a3df330eddf565f2 to your computer and use it in GitHub Desktop.
return the total physical memory usage (in MB) of all process with a given name usage: $ ./totalmem.sh chrome
#!/bin/bash
BASENAME=`basename "$0"`
TOTALMEM=0
if (( "$#" == 1 )); then
while read -r line; do
temp=$(echo "$line" | grep $1 | grep -o -E "[0-9]{2,}")
TOTALMEM=$(( $temp+$TOTALMEM ))
done < <(ps -eo comm,rsz ) # process substitution
else
echo -e "Usage: $BASENAME <process name>\n"
exit 1
fi
TOTALMEM=$(( $TOTALMEM / 1024 ))
echo "${TOTALMEM} MiB"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment