This problem occurred to me when I was contributing with Folding@Home project of Stanford University. Their application (also known as fahclient) was using all my computers CPU and the temperature of my Mac’s graphic card was around 89 degrees centigrade. So I tried to limit the CPU usage of this application within it’s preferences menu, but it was not working at all, so I searched Internet and I found that this is a common problem an the solution was not that well-known ! So in this post I’m going to describe how to limit application CPU usage in Mac OSx. In this tutorial I’m going to use cputhrottle which is a small OS X command-line utility designed to limit the CPU usage of a process to which it attaches.
First of all I should say that I used this solution for OSX 10.8.3 and it is working perfectly.
These are the steps you should go through to get this done:
- Download cputhrottle application
- Almost setup the cputhrottle application
- Limit the process using cputhrottle
1. Download cputhrottle application
In this step you should download the cputhrottle from it’s website:
You have two option to download, but I prefer the binary version (cputhrottle.gz), and I’m describing the binary version in this tutorial.
>>> Update: the willnolan website is down at the moment, <<<<
>>> so you can download the application from the link below <<<<
2. Almost setup the cputhrottle application
First open the terminal and navigate to your download folder, in my case:
You can follow the instructions from it’s website and I’m just copying those instruction here:
You must run “chmod +x cputhrottle” after running “gunzip cputhrottle.gz”, in order to make the program executable. Otherwise, it will not start correctly. Some folks have noted that gunzip says that the file is not in gzip format. In that case, try renaming the file to “cputhrottle” and running as-is.
In my experience, I got the gzip error:
gzip: cputhrottle.gz: not in gzip format
so I just renamed the file by the following command:
mv cputhrottle.gz cputhrottle
Then it is time to set the execution permission for this file:
chmod +x cputhrottle
3. Limit the process using cputhrottle
This step is the only step you should do whenever you want to limit some process CPU usage. first use the following command to get the PID of your desired process:
which will result this:
PID COMMAND %CPU TIME #TH #WQ #PORT #MREG
13004 top 5.4 00:01.80 1/1 0 24 31
13000 mdworker 0.0 00:00.05 3 1 55 66
12983 LKDCHelper 0.0 00:00.00 3 1 34 45
12981 com.apple.iC 0.0 00:00.08 4 2 55 67
12980 taskgated 0.0 00:00.03 3 1 31 60
12897 ocspd 0.0 00:00.11 1 0 25 45
12870 mdworker 0.0 00:03.48 4 1 57 95
12842 bash 0.0 00:00.01 1 0 21 26
12841 login 0.0 00:00.02 2 1 33 67
12837 cputhrottle 0.1 00:02.80 1 0 17 22
12789 FahCore_a4 200.3 15:15.36 5 0 26 205
12786 FAHCoreWrapp 0.0 00:01.29 2 0 23 74
12782 FAHControl 0.5 00:23.38 6 3 104 354
You can also use the following command to see the most demanding running processes in your computer:
top -o cpu
so now finding the PID is not hard due to the massive amount of CPU usage. In this case the file named FahCore_a4 is using 200.3% of my CPU and the PID of it is 12789. So I use the following command to limit it’s CPU usage to only 25%:
sudo ./cputhrottle 12789 25
So in the command above, the first number is the PID of your desired process and the second number is the percentage you want this process to use.
The only step left is typing your administrative password because you used sudo command.
4. Optional step – Keep the software running
As you can see in the comments, some users face this problem that the cputhrottle terminated out of sudden after few hours of running and their cpu usage were uncontrolled after that, so one of the folks was kind enough to write a shell script to check the status of this software and run it again if it was terminated.
The shell script can be accessed from Maui’s githup:
Just get the code and put it in the same directory as cputhrottle, then open it in you favorite text editor (I personally use nano)
Now you can configure the settings you like, then you should set the permission so that the code can get executed:
chmod +x throttler.sh
and now everything is good to go and you should run the shell code so it do it’s job: