Last active
February 14, 2018 12:07
-
-
Save KakersUK/e7f73622f8b957c2d952e36def343124 to your computer and use it in GitHub Desktop.
This BASH script will disable/enable the OOM (Out of Memory) killer for a given process(es)
This file contains 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 | |
if [ "$1" = "disable" ]; then | |
for PID in $(pgrep $2 | grep -v oomkiller); do | |
oomValue=$(cat /proc/$PID/oom_adj) | |
if [ $oomValue == 0 ]; then | |
echo -17 > /proc/$PID/oom_adj | |
fi | |
done | |
exit 0 | |
fi | |
if [ "$1" = "enable" ]; then | |
for PID in $(pgrep $2 | grep -v oomkiller); do | |
oomValue=$(cat /proc/$PID/oom_adj) | |
if [ $oomValue == -17 ]; then | |
echo 0 > /proc/$PID/oom_adj | |
fi | |
done | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add file to /usr/local/sbin as "oomkiller" then it can be called as such:
oomkiller disable httpd
oomkiller enable httpd