Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Last active December 6, 2016 04:22
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 mgeeky/7e34699c82f3b215a04f3155c6d4d78b to your computer and use it in GitHub Desktop.
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.
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"
@mgeeky
Copy link
Author

mgeeky commented Nov 18, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment