Last active
February 21, 2019 09:51
-
-
Save fanyeren/d5bc1b4db467e71a63a08331f7ac89d8 to your computer and use it in GitHub Desktop.
计算所有 oom score 大于 100 的 pid 和 对应的 cmdline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for score_file in `ls /proc/*/oom_score 2>/dev/null`; | |
do | |
score=$(cat $score_file 2>/dev/null); | |
if [[ x$score != 'x' ]]; then | |
if [[ $score > 100 ]]; then | |
pid=$(echo $score_file 2>/dev/null | awk -F'/' '{print $3}') | |
if [[ x$pid != 'x' ]]; then | |
cmdline=$(cat /proc/$pid/cmdline 2>/dev/null | tr '\000' ' ') | |
if [[ x$cmdline != 'x' ]]; then | |
echo $pid, $score, $cmdline >> /tmp/cmdline | |
fi | |
fi | |
fi | |
fi | |
done | |
# 怎么用呢? | |
# 排序目前 oom score 最大的 pid,也就是被 oom-killer 风险最大的进程:cat /tmp/cmdline | sort -rnk2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment