Last active
December 6, 2016 04:22
-
-
Save mgeeky/7e34699c82f3b215a04f3155c6d4d78b to your computer and use it in GitHub Desktop.
Bash oneliner counting number of bytes occupied by chosen (by PID) process. It works by iterating /proc/$PID/maps file, then computing each memory region range size, then adding it together. Kinda slow though.
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
PID=<PID>; BYTES=`IFS=$'\n'; for l in $(cat /proc/$PID/maps | cut -d' ' -f1 | awk -F '-' '{printf "0x%s-0x%s\n", $2, $1}'); do echo $l | ruby -e 'print "#{eval(STDIN.read)}\n"'; done | paste -sd+ - | bc`; echo "Bytes occupied by PID=$PID : $BYTES" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worth to mention - it is terribly bad at performance, having written this oneliner I realized we can use
/proc/$PID/smaps
to obtain the same result much faster.