Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I would like to limit the amount of CPU time dedicated to certain processes (e.g. Firefox, Safari, ...).

I can't understand why such programs, even when not used (nothing loading, no animations, running in the background, ...), are so resource hungry. Why a browser must eat 50% or more of my CPU? Can I limit it to 10%?

Thank you.

share|improve this question
1  
No this is not possible. With all due respect, the point of a system is to get used. Letting CPU cycles go to waste is utterly pointless. You might as well just downgrade your system if you plan on doing that. Just out of curiosity, what do you hope to gain? In other words, may I ask why you would want to do this? –  cksum Sep 14 '11 at 10:05
1  
If I have a process that needs the CPU to do serious work, and this is busy with a browser I am not even using, it is not an optimal use of resources. And when running on batteries, having a process that keeps the CPU busy doing nothing is not good. –  Pietro Sep 14 '11 at 10:30
2  
One might also be giving yourself "working room". For example, I have a process that will tie up my entire processor for the better part of an hour. I'd rather it take two hours but my computer be usable in that time. –  Fomite Sep 19 '11 at 21:22
1  
@cksum this is possible. –  faraz May 5 '12 at 2:44

5 Answers 5

up vote 2 down vote accepted

You can monitor a series of processes by name by running the Bash script below. I'm not quite sure how to turn this into a login item since cputhrottle requires superuser permissions. Run it as a script, in an Automator workflow, whatever:

# Get the Process/App names from Activity Monitor and put them here
apps=("AppOne" "AppTwo" "AppThree")
# Set the respect limits here
limits={30 40 50)

while true; do
  for ${app} in ${apps}; do
    for ${limit} in ${limits} do
      for pid in `pidof ${app}`
        sudo /path/to/cputhrottle ${pid} ${limit}
      done
    done
  done
done
share|improve this answer

You can indeed! There's CPUThrottle, which allows to specify a PID to restrict.

Note, they're trying to use that much for a reason, it's a useful tool but whether it'll make it better or worse for you on a day to day will be something you discover.

share|improve this answer
    
Interesting. But with this utility I have to launch a program, find its PID(s) and manually use cputhrottle. Every time I launch it. Is there something that allows me to tell the system: “From today always run this program with a maximum of 25% CPU” ? –  Pietro Sep 14 '11 at 10:45
    
As far as I'm aware no, I've only ever come across CPUThrottle. –  Nicholas Smith Sep 14 '11 at 11:03

Its not exactly what you wanted, but, in regards of google drive and chrome this what did the trick for me:

for f in $(pgrep Drive; pgrep Chrome); do renice -n +20 -p $f ; done
share|improve this answer

Although not a direct answer to the OP's question, if you're having an issue with a particular process taking up too much of your CPU time, and making your computer unusable, and you don't mind how long that process takes to finish the task it's working on, you can use the renice to alter the priority of that process, making it behave nicely (hence the name).

First, you need to find the PID of the process that's using up the CPU resources. You can either do that in Activity Monitor, or in Terminal.app with the ps command - e.g. to find the PID of the Safari browser, type:

MacBook:~😈  ps -ef | grep Safari
  501 17452   263   0 11:36pm ??         4:15.60 /Applications/Safari.app/Contents/MacOS/Safari

The second line above is the output, and the PID is 17452 in this particular case.

Then, the next task is to change the priority of the process (let's say it's Safari we want to make behave nicely). To do this, in Terminal.app type:

MacBook:~😈  renice -n 10 -p 17452

The -n option changes the nice level by adding 10 to the current value (0 by default). The range of values are -20 to 20, with lowest value meaning highest priority. As an ordinary user, you can use values 0 to 20. To assign a negative value, you need to have root privileges (e.g. use sudo command). Read more about nice and renice by typing man nice and man renice in Terminal.app.

nice and renice don't limit the percentage of the CPU available to a given application per se, they do however allow to change the scheduling priority, or in other words how much of the CPU time a process will get. This is all relative to the CPU load on your system, so if the system is under utilised, you most likely won't see any difference.

share|improve this answer

The link that Nicholas Smith posted doesn't work anymore. So I found one other app that does the trick for the people who are searching it again. the app calls Apppolice.

http://www.macupdate.com/app/mac/49836/apppolice

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.