Skip to content

Instantly share code, notes, and snippets.

@duzun
Created March 15, 2017 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duzun/8f493bd5f42a5835bac507ce708451fa to your computer and use it in GitHub Desktop.
Save duzun/8f493bd5f42a5835bac507ce708451fa to your computer and use it in GitHub Desktop.
Process Memory consumption - Linux
#!/bin/bash
#############################################
# Process Memory consumption #
# #
# Usage: psmem <process_name> [<user_grep>] #
# psmem nginx #
# psmem php5-fpm www-data #
# #
# Author: Dumitru Uzun (DUzun.me) #
#############################################
p=$1
g=$2
h=rss # cmd
[ ! -z "$g" ] && h=$h,user
list() {
if [ -z "$g" ]; then
ps --no-headers -o "$h" -C $p
else
ps --no-headers -o "$h" -C $p | grep $g
fi
}
c=`list | wc -l`
echo -n \"$1\" "RAM: "
if [ "$c" -gt 0 ]; then
echo -n `list | awk '{ sum+=$1 } END { printf ("%s%d%s", "~", sum/NR/1024,"M") }'` x$c" = "
echo `list | awk '{ sum+=$1 } END { printf ("%d%s", sum/1024,"M") }'`
else
echo none
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment