Created
February 21, 2018 18:27
-
-
Save gamort/1b9379ce8f30d07932be9a416cf17f55 to your computer and use it in GitHub Desktop.
Throttle hyperkit
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
#!/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