#!/bin/bash export DISPLAY=":0.0" CPU_LIMIT_FILE="$AOTDIR/aot_cpu_limit" CURRENT_LIMIT=0 # Initialize the CPU limit file with AOT_CPU_LIMIT if it's set if [ ! -z "$AOT_CPU_LIMIT" ]; then echo "$AOT_CPU_LIMIT" > "$CPU_LIMIT_FILE" fi # give the x server time to start sleep 5; while true; do if [ -f "$CPU_LIMIT_FILE" ]; then NEW_LIMIT=$(cat "$CPU_LIMIT_FILE") # Validate NEW_LIMIT is a number greater than zero if [[ "$NEW_LIMIT" =~ ^[0-9]+$ ]]; then # Check if the limit has changed if [ "$NEW_LIMIT" -ne "$CURRENT_LIMIT" ]; then # If so, update CURRENT_LIMIT CURRENT_LIMIT="$NEW_LIMIT" # Kill existing cpulimit process if any AOT_PID=$(pidof AgeOfTime.exe) CPULIMIT_PID=$(pgrep -fl "cpulimit.*\-p $(pidof AgeOfTime.exe)" | awk '{print $1}') if [ ! -z "$CPULIMIT_PID" ]; then echo "Killing cpulimit process $CPULIMIT_PID" kill "$CPULIMIT_PID" fi # Apply new cpulimit if >= 0 if [ ! -z "$AOT_PID" ] && [ "$NEW_LIMIT" -gt 0 ]; then echo "Creating cpulimit process (limit=$NEW_LIMIT)" cpulimit -p "$AOT_PID" -l "$NEW_LIMIT" -b & fi fi fi fi if wmctrl -l | awk '{$3=""; $2=""; $1=""; print $0}' | grep '^\s*Program Error$'; then kill $(pidof AgeOfTime.exe) kill $(pidof winedbg) fi sleep 1 done