Skip to content

Instantly share code, notes, and snippets.

@hpsaturn
Created July 15, 2018 19:32
Show Gist options
  • Save hpsaturn/360801ea6c53ed38f4dd0e2d0d84896f to your computer and use it in GitHub Desktop.
Save hpsaturn/360801ea6c53ed38f4dd0e2d0d84896f to your computer and use it in GitHub Desktop.
Get the total of memory from a procces and her threads
#!/bin/bash
cmd=$1
mem=`ps -eo %mem,cmd --sort=-%mem | grep -i $cmd | awk -F ' ' '{sum += $1} END {print sum}'`
memtotal=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
memcmd=`awk 'BEGIN{printf "%.2f\n", (("'$mem'"*"'$memtotal'")/100000)}'`
echo "${memcmd} Mb (${mem}%)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment