Limit application CPU usage in Mac

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:

  1. Download cputhrottle application
  2. Almost setup the cputhrottle application
  3. Limit the process using cputhrottle

 

1. Download cputhrottle application

In this step you should download the cputhrottle from it’s website:

http://www.willnolan.com/cputhrottle/cputhrottle.html

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   <<<<

http://www.4shared.com/archive/OsVyev_y/cputhrottle.html

2. Almost setup the cputhrottle application

First open the terminal and navigate to your download folder, in my case:

cd ~/Downloads/

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:

top

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:

https://github.com/maumi/cputhrottle

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)

nano throttler.sh

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:

sh ./throttler.sh

21 thoughts on “Limit application CPU usage in Mac”

  1. NIce utility. I’ve got an old windows program MSMoney running in wine which chews up cpu (also does this in native windows) so nice to be able to use this on wine to drop down to low levels.
    Thanks
    Chris

  2. I can’t find the binary anymore. Googling for cputhrottle.gz I found the file but it gives me the source code and I don’t have the dev environment installed. Could someone please post a working link to the binary?

    Much appreciated!

    1. Hi Max

      I checked the link and I realised that the website willnolan.­com is not working. I shared it in the post. as soon as he got his site fixed, I will remove this alternative link.

  3. My old MacbookPro6,1 thanks you for extending his life a little longer.

    Only question, is there a command to remove the process limit or should I just ./cputhrottle PID 100x#OfCPUCores ?

    Regards,
    Sean

    1. You are mostly welcome 😉

      About your question, the only thing you should do to remove the limitation created by cputhrottle is to simply close the terminal or press ^C (control + c) to terminate the execution of cputhrottle.

  4. Hi.

    Much good Karma to you for this! It makes running a bitcoinwallet on a Mac laptop just as quiet as the Mac´s are supposed to be. 🙂

    Kind regards

  5. Is there any way to make this permanent? I am using this for a shockwave flash plugin that keeps using 200% CPU, but it is not always active. How can I make my limits stay, even after the process quits?

    1. No, there is no option in this application which you can permanently run this app. I think you should do some bash coding to check the status of the process name you want and run the cputhrottle whenever that process is running.

  6. I have the correct permissions set and can execute cputhrottle, but it keeps terminating on its own. I must keep issuing the command.

    Any thoughts?

    1. The only condition the cputhrottle terminates it self is when the process ID ends, perhaps the process you are trying to limit restarts frequently and gets new ID everytime it starts. I don’t know any other condition, but perhaps you can contact the developer and ask for further advice regarding of your OS version and the process you want to limit.

  7. Thanks for the reply. Just to clarify:
    1. I start Handbrake to encode a file.
    2. I start cputhrottle via the CLI with the appropriate PID and percentage (e.g. 50%)
    3. I keep the terminal window open and I notice the cputhrottle process had ended and the CLI is returned.
    4. I press the UP arrow to repeat the last command in the buffer and press enter again. I don’t have to change the PID information as it is the same.
    5. I continue to do this until the encoding is complete.
    6. I use Activity Monitor to watch both processes and CPU utilization and can see the CPU spike as soon as the cputhrottle process ends.

  8. Does this tutorial require XCode to be installed on the mac?

    I keep getting the error: cannot execute binary file

    I followed all the steps. Pl. help.

    Jason.

    1. I don’t think so, but since I already have XCode on my Mac, I can’t tell. But I believe you should be able to run this without having XCode fully installed.

      But if you still have that problem, paste your commandline here, so I can re-check what you are typing and what procedure are you going through.

  9. Hey josh, richie

    i know it’s been a time since the last comment but I had the same problem like Richie. After some hours cputhrottle closes without any failure. Because I use it over night to get my fan speed down it is bad if its just closing (temperature rising).
    So I wrote a minmal bash script which looks if cputhrottle is still open and if not open it again.
    If any of you are interested in the script, just text me her and I will upload it.
    Greetz
    Maui

    1. Hi Maui,

      Though I still don’t know what causes this program to get terminated, but having such code that checks the running state of this program is more than good since high cpu temperature may cause hardware damage.
      Perhaps it’s a good idea to submit your code in github and give me (Nixsos Admin) the link so I can put it under your name in the article.

      Yours;

    1. Thanks, I just added a last optional section to the article. Please let me know if you want to represent your name in any specific way.

  10. Nope. It’s ok so.
    But I thing you’ve made a little typo in this section. It should be chmod +x because you want to add executable permission.
    If you find some failures in the script feel free to commit.

  11. Hi guys. Any way to make it work under El Capitan? I am unable to gunzip the file. I have changed filename etcetera, but still gets this message:

    gunzip: can’t stat: cputhrottle (cputhrottle.gz): No such file or directory
    Tests-MacBook-Pro-2:Downloads test$

Leave a Reply

Your email address will not be published. Required fields are marked *

This is new type of CAPTCHA, make the puzzle please !WordPress CAPTCHA