Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run distributed computing projects, which typically want to use 100% of the CPU. How do I limit the CPU usage in terms of temperature instead of percent usage? Also, what is the maximum safe temperature to keep an Intel i5 running 24/7? (With no CPU limit FahCore_a4 causes this machine to run at 82 degrees Celsius.)

share|improve this question

On this webpage there is a bash script that will attempt to keep your CPU below a specified temperature.

You just need to provide it with your desired maximum temperature, and it will throttle your CPU(s) in an effort to stay below that temperature.

Shameless plug- I wrote and maintain the above script.

share|improve this answer
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – fossfreedom Nov 19 '12 at 16:47
nice script.. good idea :) – Superbiji Mar 29 '14 at 3:21
here are essential parts: – DmitrySandalov Jul 17 '14 at 20:14

Here is how I solved it using bash. If anyone comes up with a better daemon (better at staying near the target temperature) please post it.


    while true; do
            val=$(sensors | awk '/Core 0/ {print $3}')
            max=$(echo "+60.0")
            if [[ "$val" < "$max" ]]
                            killall cpulimit
                            sleep .1
                            cpulimit -e FahCore_a4 -l 99 &
                            sleep 1
    exit 0
share|improve this answer

This is how I solved my overheating problems which were not caused by a specific process, but by failure of my laptop to dissipate the heat caused by running on a high CPU load for longer periods of time. The main difference to the solution offered by da code monkey himself is that I use cpu frequency scaling, instead of using cpulimit on a specific process. Since I have Psensor installed and running anyway, I piggyback on Psensor. A daemon like da code monkey suggested should also work, however two thresholds (min and max) are required. In Psensor (Sensor Preferences->Alarm) I set an alarm for the relevant sensor if becomes higher than the high threshold (I use 85) or lower than the low threshold (I use 80). In Preferences->Sensors->Script executed when an alarm is raised I call my script like this:

/ALLUSER/ powersave ondemand 82

The first parameter is a valid scaling_governor which reduces CPU frequency, e.g. powersave. The second parameter is the default scaling_governor - ondemand for most systems. The third parameter is a temperature between low and high threshold (the exact value is not important). Psensor adds two more parameters: a sensor id and the temperature reported.

And this is my script:

 # TempNZ is temperature reported by Psensor; strip of trailing °C
bnum=`expr index "$TempNZ" "°"`
if (( bnum < 2 )); then
    echo "ERROR"
# Is this a low threshold alarm?
if [ "$TempNZ" -le "$3" ]; then
sudo sh -c "echo '$STR' > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
# echo new scaling_governor
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# play sound - audio feedback - optional
paplay /usr/share/sounds/ubuntu/stereo/message-new-instant.ogg

Works fine for me (UBUNTU 14.04 LTS).

Being a novice to Linux and bash, I used a number of resources, including:

share|improve this answer

The CPU itsself has a mechanism where it powers itsself down if it gets too hot. (maybe not if you disable SMI interrupts, I'm not sure about that.)

The main user-space application is the lm-sensors package. After installing it run sensors-detect to set it up, if your machines are the same you can run this once, and use the resulting findings everywhere.

CPU frequency is easily controled via the cpufreq driver subsystem. see

You could write a daemon that uses lm-sensors to poll the temp and if its too hot turn down the cpu frequency.

share|improve this answer
what language would writing such a daemon be easiest in? bash, python, awk? – jeffythedragonslayer Aug 3 '12 at 7:43
I'd say bash is the simplest. Here's an example (look at lines 55-66). – Adobe Aug 3 '12 at 14:54

Your Answer


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.