Skip to content

Instantly share code, notes, and snippets.

@nevmerzhitsky
Last active April 10, 2018 09:15
Show Gist options
  • Save nevmerzhitsky/899e56127270cb320e0e70ad717d3b8d to your computer and use it in GitHub Desktop.
Save nevmerzhitsky/899e56127270cb320e0e70ad717d3b8d to your computer and use it in GitHub Desktop.
Wrapper of a process without OOM watching
#!/bin/bash
# Works bad with termination of children processes when started via sudo. Please, run as super-user.
if [ "$1" == "" ]; then
echo "Usage: no-oom <a line to start new process>" 1>&2
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Start a child process
$@ &
PID=$!
# To successful stop all children on the parent exit
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM
# Disable OOM watcher for the child process (-17 is correct for Ubuntu 14)
echo -17 > /proc/$PID/oom_adj
# Wait the child process to finish
wait $PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment