Skip to content

Instantly share code, notes, and snippets.

@KakersUK
Last active February 14, 2018 12:07
Show Gist options
  • Save KakersUK/e7f73622f8b957c2d952e36def343124 to your computer and use it in GitHub Desktop.
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)
#!/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
@KakersUK
Copy link
Author

Add file to /usr/local/sbin as "oomkiller" then it can be called as such:
oomkiller disable httpd
oomkiller enable httpd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment