Created
January 12, 2022 13:02
-
-
Save dionedomingo/555d231d7d82def46d986a3ddc0d93fa to your computer and use it in GitHub Desktop.
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 | |
ps -A --sort -rss -o comm,pmem,rss | awk ' | |
NR == 1 { print; next } | |
{ a[$1] += $2; b[$1] += $3; } | |
END { | |
for (i in a) { | |
size_in_bytes = b[i] * 1024 | |
split("B KB MB GB TB PB", unit) | |
human_readable = 0 | |
if (size_in_bytes == 0) { | |
human_readable = 0 | |
j = 0 | |
} | |
else { | |
for (j = 5; human_readable < 1; j--) | |
human_readable = size_in_bytes / (2^(10*j)) | |
} | |
printf "%-20s\t%s\t%.2f%s\t%s\n", i, a[i], human_readable, unit[j+2], b[i] | |
} | |
} | |
' | awk 'NR>1' | sort -rnk4 | awk ' | |
BEGIN {printf "%-20s\t%%MEM\tSIZE\n", "COMMAND"} | |
{ | |
printf "%-20s\t%s\t%s\n", $1, $2, $3 | |
} | |
' | less |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment