Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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(}\n"'; done | paste -sd+ - | bc`; echo "Bytes occupied by PID=$PID : $BYTES"

This comment has been minimized.

Copy link
Owner Author

@mgeeky 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