Skip to content

Instantly share code, notes, and snippets.

@gamort
Created February 21, 2018 18:27
Show Gist options
  • Save gamort/1b9379ce8f30d07932be9a416cf17f55 to your computer and use it in GitHub Desktop.
Save gamort/1b9379ce8f30d07932be9a416cf17f55 to your computer and use it in GitHub Desktop.
Throttle hyperkit
#!/usr/local/bin/bash
if [[ $EUID > 0 ]]; then
echo "Please run this script as root/sudo"
exit 1
fi
# Pass --kill as argument to kill all running cputhrottles
if [[ $1 = "--kill" ]]; then
echo "Looking for running cputhrottles..."
pids=`pidof cputhrottle`
for pid in ${pids}; do
echo "> Killing PID ${pid}"
sudo kill ${pid}
done
echo "Done!"
exit 0
fi
declare -a applications
# Syntax='application;max-cpu'
applications[1]='hyperkit;60'
for i in "${applications[@]}"; do
app=(${i//;/ })
app_name=${app[0]}
cpu_limit=${app[1]}
printf "\nLooking for ${app_name}...\n"
pids=`pidof ${app}`
for pid in ${pids}; do
echo "> PID=${pid}, CPU=${cpu_limit}"
sudo cputhrottle ${pid} ${cpu_limit} &
done
done
printf "\nDone!\n"
echo "Run this script passing '--kill' as argument to remove all cputhrottles."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment