Skip to content

Instantly share code, notes, and snippets.

@tiebingzhang
Last active September 6, 2017 16:29
Show Gist options
  • Save tiebingzhang/517a8494bc16ba74cf79e103dde46a9f to your computer and use it in GitHub Desktop.
Save tiebingzhang/517a8494bc16ba74cf79e103dde46a9f to your computer and use it in GitHub Desktop.
script to sort which process uses the most memory
#!/bin/sh
>/tmp/maxmem.out
>/tmp/maxmem2.out
for i in /proc/[1-9]* ; do
grep -q VmSize $i/status || continue
awk '/^VmSize:/{printf("%s ",$2);};' $i/status >> /tmp/maxmem.out
awk '/^VmRSS:/{printf("%s ",$2)};' $i/status >> /tmp/maxmem2.out
echo -n " $i " >> /tmp/maxmem.out
echo -n " $i " >> /tmp/maxmem2.out
echo >> /tmp/maxmem.out
echo >> /tmp/maxmem2.out
done
echo "----------------Sorted by VmSize"
sort -r -n /tmp/maxmem.out | head -n 10
echo "----------------Sorted by RSS Size"
sort -r -n /tmp/maxmem2.out | head -n 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment