Created
March 26, 2024 08:46
-
-
Save eusonlito/f2dc01f7738c84370face160244879de to your computer and use it in GitHub Desktop.
This script identifies the second most memory-intensive PHP process, resets the Out-Of-Memory (OOM) priority of the previously adjusted process if still running, sets the current process's OOM priority to be more likely killed, and logs its PID and timestamp.
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 | |
APP="php" | |
CURRENT_HIGHEST=$(ps -eo pid,comm --sort=-%mem | grep "$APP" | head -n 2 | tail -n 1) | |
CURRENT_HIGHEST_PID=$(echo $CURRENT_HIGHEST | awk '{print $1'}) | |
LAST_PID_FILE="/tmp/oom-kill-previous" | |
if [ -f "$LAST_PID_FILE" ]; then | |
LAST_PID=$(cat $LAST_PID_FILE) | |
if [ "$LAST_PID" != "" ] && [ -d "/proc/$LAST_PID" ]; then | |
echo 0 > /proc/$LAST_PID/oom_score_adj | |
fi | |
fi | |
echo 1000 > /proc/$CURRENT_HIGHEST_PID/oom_score_adj | |
echo $CURRENT_HIGHEST_PID > $LAST_PID_FILE | |
echo "[$(date --iso-8601=seconds)] $CURRENT_HIGHEST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment