-
-
Save yuchen/6b770e418e11a9e460c7c5f229bfeec3 to your computer and use it in GitHub Desktop.
Revisions
-
golimpio revised this gist
Mar 24, 2017 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ if [ $1 = "--kill" ]; then echo "> Killing PID ${pid}" sudo kill ${pid} done printf "Done!\n\n" exit 0 fi @@ -35,7 +35,7 @@ set_cpu_limit() { service_cpu=$(ps aux | grep "sudo cputhrottle $pid $cpu_limit" | grep -v grep | wc -l) if [[ ! $service_cpu -gt 0 ]]; then sudo cputhrottle $pid $cpu_limit & printf "\n" else printf " [already running]\n" fi @@ -44,17 +44,16 @@ set_cpu_limit() { declare -a applications # Syntax='application-name;max-cpu%(1-100)' applications[0]='Chrome;50' applications[1]='idea;65' applications[2]='pycharm;40' applications[3]='webstorm;40' applications[4]='datagrip;40' 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 @@ -63,4 +62,4 @@ for i in "${applications[@]}"; do done printf "\nDone!\n" printf "Run this script passing '--kill' as argument to remove all cputhrottles.\n\n" -
golimpio revised this gist
Mar 23, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ set_cpu_limit() { declare -a applications # Syntax='application-name;max-cpu%(1-100)' applications[0]='Chrome;40' applications[1]='idea;50' applications[2]='pycharm;40' -
golimpio revised this gist
Mar 23, 2017 . 1 changed file with 21 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,26 @@ if [ $1 = "--kill" ]; then exit 0 fi # Start cputhrottle if it's not running yet for the given PID set_cpu_limit() { pid=$1 cpu_limit=$2 if [[ "$pid" == "" || "$cpu_limit" == "" || $cpu_limit -lt 1 || $cpu_limit -gt 100 ]]; then echo "! Invalid arguments: pid=$pid, cpu_limit=$cpu_limit" return fi printf "> PID=${pid}, CPU=${cpu_limit}" service_cpu=$(ps aux | grep "sudo cputhrottle $pid $cpu_limit" | grep -v grep | wc -l) if [[ ! $service_cpu -gt 0 ]]; then sudo cputhrottle $pid $cpu_limit & printf " [started]\n" else printf " [already running]\n" fi } declare -a applications # Syntax='application;max-cpu' @@ -38,8 +58,7 @@ for i in "${applications[@]}"; do printf "\nLooking for ${app_name}...\n" pids=`pidof ${app}` for pid in ${pids}; do set_cpu_limit ${pid} ${cpu_limit} done done -
golimpio revised this gist
Mar 23, 2017 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ #!/bin/bash # Run cputhrottle for a list of applications in order to limit their CPU usage. # This script needs `pidof` and `cputhrottle` installed, which can be installed from homebrew. # NOTE: This script was tested on MacOS only. if [[ $EUID > 0 ]]; then echo "Please run this script as root/sudo" exit 1 -
golimpio created this gist
Mar 23, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ #!/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[0]='Chrome;40' applications[1]='idea;50' applications[2]='pycharm;40' applications[3]='webstorm;40' applications[4]='datagrip;35' 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."