Created
March 15, 2017 08:33
-
-
Save duzun/8f493bd5f42a5835bac507ce708451fa to your computer and use it in GitHub Desktop.
Process Memory consumption - Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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