Created
December 11, 2017 20:02
-
-
Save jhyland87/cb7852871111be41668cc69c41bc6271 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
declare -A cfg | |
cfg['app']='com.microsoft.Outlook' | |
cfg['limit']='20' | |
proc_pid=$(lsappinfo info ${cfg['app']} -only pid | cut -d '=' -f2) | |
if [[ -z ${proc_pid} ]]; then | |
echo "Unable to find Outlook running" 1>&2 | |
exit 1 | |
fi | |
echo "Found app for ${cfg['app']} (pid ${proc_pid})" | |
#lsappinfo info ${proc_pid} | |
ps aux | grep "[c]puthrottle ${proc_pid}" &>/dev/null | |
if [[ $? -ne 0 ]]; then | |
echo -n "Found some existing cputhrottle processes for PID ${proc_pid} - Killing processes... " | |
ps -a -o pid,args | grep "[c]puthrottle ${proc_pid}" | cut -d' ' -f1 | xargs sudo kill -9 &>/dev/null | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to kill existing cputhrottle processes." 1>&2 | |
exit 1 | |
fi | |
echo "Done" | |
fi | |
echo -n "Setting CPU throttle limit for PID ${proc_pid} to ${cfg['limit']}... " | |
sudo cputhrottle ${proc_pid} ${cfg['limit']} & disown &>/dev/null | |
if [[ $? -ne 0 ]]; then | |
echo "Failed." 1>&2 | |
exit 1 | |
fi | |
echo "Done" | |
echo -e "\n\nTo monitor the process, try running: sudo htop --pid=${proc_pid}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment