Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Run cputhrottle for a list of applications in order to limit their CPU usage.
  4. # This script needs `pidof` and `cputhrottle` installed, which can be installed from homebrew.
  5. # NOTE: This script was tested on MacOS only.
  6.  
  7. if [[ $EUID > 0 ]]; then
  8. echo "Please run this script as root/sudo"
  9. exit 1
  10. fi
  11.  
  12. # Pass --kill as argument to kill all running cputhrottles
  13. if [ $1 = "--kill" ]; then
  14. echo "Looking for running cputhrottles..."
  15. pids=`pidof cputhrottle`
  16. for pid in ${pids}; do
  17. echo "> Killing PID ${pid}"
  18. sudo kill ${pid}
  19. done
  20. echo "Done!"
  21. exit 0
  22. fi
  23.  
  24. declare -a applications
  25.  
  26. # Syntax='application;max-cpu'
  27. applications[0]='Chrome;40'
  28. applications[1]='idea;50'
  29. applications[2]='pycharm;40'
  30. applications[3]='webstorm;40'
  31. applications[4]='datagrip;35'
  32.  
  33. for i in "${applications[@]}"; do
  34. app=(${i//;/ })
  35. app_name=${app[0]}
  36. cpu_limit=${app[1]}
  37.  
  38. printf "\nLooking for ${app_name}...\n"
  39. pids=`pidof ${app}`
  40. for pid in ${pids}; do
  41. echo "> PID=${pid}, CPU=${cpu_limit}"
  42. sudo cputhrottle ${pid} ${cpu_limit} &
  43. done
  44. done
  45.  
  46. printf "\nDone!\n"
  47. echo "Run this script passing '--kill' as argument to remove all cputhrottles."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement