add script to calculate OOM score of a process

This commit is contained in:
Oliver Ladner 2023-11-02 09:40:00 +01:00
commit 31c999bdb6

5
oom_score.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# Displays running processes in descending order of OOM score
# Source: https://dev.to/rrampage/surviving-the-linux-oom-killer-2ki9
printf 'PID\tOOM Score\tOOM Adj\tCommand\n'
while read -r pid comm; do [ -f /proc/$pid/oom_score ] && [ $(cat /proc/$pid/oom_score) != 0 ] && printf '%d\t%d\t\t%d\t%s\n' "$pid" "$(cat /proc/$pid/oom_score)" "$(cat /proc/$pid/oom_score_adj)" "$comm"; done < <(ps -e -o pid= -o comm=) | sort -k 2nr