Created
March 31, 2018 21:27
-
-
Save farhany/bb423fb7c8d567b12d6db47a1e05959c 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
# https://superuser.com/questions/665030/is-it-possible-to-format-ps-rss-memory-output-to-be-more-human-friendly | |
# credit to https://superuser.com/users/261502/pono who write this script | |
# get terminal width | |
WIDTH=`tput cols` | |
# pipe stdin to awk | |
cat | \ | |
awk '\ | |
BEGIN { | |
# set output format | |
CONVFMT="%.2f" | |
} | |
NR==1 { | |
# search first line for columns that need to be converted from K to M | |
for (i=1;i<=NF;i++) | |
# add condition for new columns if you want | |
if ($i=="VSZ" || $i=="RSS") { | |
# column numbers are stored in an array | |
arr[i]=i; | |
$i = $i "(MB)" | |
} | |
} | |
NR > 1 { | |
# edit appropriate columns | |
for (i in arr) | |
$i=$i/1024; | |
} | |
{ | |
# print every line | |
print $0 | |
}' | \ | |
# format the output into columns and trim it to terminal width | |
column -t | cut -c 1-$WIDTH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment