Skip to content

Instantly share code, notes, and snippets.

@jnerin
Last active August 29, 2015 13:57
Show Gist options
  • Save jnerin/9842753 to your computer and use it in GitHub Desktop.
Save jnerin/9842753 to your computer and use it in GitHub Desktop.
oneliners to explore the oom_score* values
#!/bin/bash
# Linked from: https://plus.google.com/+JorgeNer%C3%ADn/posts/3zdnEnXFN7Z
# Some oneliners to explore the oom_score* values:
# Processes with oom_score_adj != 0:
grep . /proc/*/oom_score_adj | grep -v ":0" | grep -v self | perl -ne 'm@/([0-9]+)/oom_score_adj:(-?[0-9]+)@; ($pid,$score)=($1,$2); open FILE,"<","/proc/$pid/cmdline"; $cmd=<FILE>; $cmd=~s/\0.*//; close FILE; print "$score\t$pid\t$cmd\n"; '
# In my system the results sumarized are:
# adj name
# -1000 udevd & sshd
# 100 chrome --type=plugin
# 200 chrome --type=gpu-process
# 300 chrome --type=renderer
# 300 spotify-client/Data/SpotifyHelper
# Evil process, the one with highest badness oom_score (two options):
ps $(grep . /proc/*/oom_score|grep -v ":0"|grep -v self|sort -t: -nrk2|head -1|cut -d/ -f3)
# Hint, explainshell: http://explainshell.com/explain?cmd=grep+.+%2Fproc%2F*%2Foom_score+%7Cgrep+-v+%22%3A0%22+%7C+grep+-v+self%7C+sort+-t%3A+-k+2+-n+-r+%7C+head+-1+%7Ccut+-d%2F+-f+3
# And a second option, this one with three columns (score, pid, cmd):
grep . /proc/*/oom_score |grep -v ":0" | grep -v self | perl -ne 'm@/([0-9]+)/oom_score:(-?[0-9]+)@; ($pid,$score)=($1,$2); open FILE,"<","/proc/$pid/cmdline"; $cmd=<FILE>; $cmd=~s/\0.*//; close FILE; print "$score\t$pid\t$cmd\n"; ' |sort -nr |head -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment