6 ms·
Print RAM Usage of process including children
Prints resident set size (RAM) usage of processes including $1 in their name (includes children):
function ram() {pgrep -f $1 | xargs -I{} pmap -x {} | grep total | python -c "import sys; print('%.2f' % (sum([float([c for c in line.strip().split(' ') if c][3]) for line in list(sys.stdin)])/1024), 'MB RAM')"}
Been looking for a way to see total RAM usage of processes including their children, after a bit of googling I came up with this ugly one liner, but hey it works!
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- darfo 6y agoGot working after I figured out the argument should be the command I’m interested in. And it must be run as root if not my process because of pmap -x One-liners are cool.
- sean_pedersen 6y agoYup usage is simple: $ ram firefox Will print total firefox RAM usage. On my machine (Arch Linux) it works without root...
- deleted 6y ago[deleted]
- torqu3e 6y agoAll bash version of it... pgrep -f $1 | xargs -I{} pmap -x {} | grep total | awk '{sum=sum+$4}END{printf "%.2f%s", sum/1024," MB\n"}' e.g. $ pgrep -f bash | xargs -I{} pmap -x {} | grep total | awk '{sum=sum+$4}END{printf "%.2f%s", sum/1024," MB\n"}' 74.79 MB