Monday, October 29, 2012

Linux: Cool your CPU temperature with frequency throttling

Last night I went to sleep while running a heavy program that used 100% of my Intel i7 multicore processor. When I woke up in the morning, I found my laptop powered off. A look through the /var/log/syslog confirmed that it had shut off due to over heating.

So to control temperature, I wrote a script to throttle cpu frequency. This script must be run with root privileges (sudo) to work. For a desired max temperature of 80 degrees Celsius, use a command like this:
sudo ./ 80

This can also result in longer battery life on laptops and portable devices.

Download link: temperature throttling script for Linux -
New User Resources:

Download link: temperature throttling script for Linux -

Project source page:

NOTICE: This script may not be effective if your system over heating is due to factors other than your CPU (ie. graphics, harddrive, etc.). This script will only throttle your CPU frequency based on your systems reported temperature. Opening and cleaning dust from a computer can often dramatically help cool it also.

If this script helps you in any way, please pay me with a message of thanks, and share this page with others.

Comment or leave feedback sepero 111 @ gmx . com

overheating cpu scaling temperature control Linux


  1. Hi, nice script! umm, my /sys/class/hwmon/hwmon0/temp1_input
    always reports 42 C, so I changed that line to
    TEMP=$(cat /sys/class/hwmon/hwmon1/device/temp1_input)
    that reports the temp the same as my gkrellm lm_sensors CPU temp monitor.


    1. Thanks for the info, Willem. I've updated the code to hopefully accommodate more people.

    2. I am running Fedora 19 and I had to change that path to
      Please note that the device directory does not have temp1_input. This took a little while for me to figure out.

      After I changed this my machine runs beautifully. Also, Pedro's method for running the script as root worked wonders.

      This makes my machine usable again. I also have an i7 but my biggest has always been that it will burn up to the critical temperature and shut off.

      Thanks so much!

  2. Finally! I've found you!
    I published your script at I wanted to ask your permission, but lost your blog :) Sorry.

    And more.
    Some people have even more problems, their kernel module for cpu frequency controlling not loading automatically. I have seen it on arch, mandriva/mageia/rosa, fedora, opensuse (hey! they all rpm distros!) and if you work on laptop without frequency control - huh, it gets hot!
    I don't want to dig deeper into why is this happening, I just wrote autostart script for starting your script with automatic detection if selected module loaded and loading module with selected governor.
    Script was written for RosaLinux/Mageia/Mandriva/Fedora, but I think you can easilly adopt it for Ubuntu or anything else (only change path to /sys/.../cpufreq folder and change comand cpupower to cpufreq-set (or write your own :) )

  3. Hi Russian friend, thank you for sharing. I'm glad it worked out great for you. :)

  4. Thank you very much Sepero, this script works very well in Fedora 18, no more shutdowns while watching Youtube videos...

    Just want to add the simple instructions to run the script on boot as root in Fedora 18:

    Create rc.local:

    # touch /etc/rc.d/rc.local

    Make it executable:

    # chmod +x /etc/rc.d/rc.local

    Open rc.local and add the following text:


    /root/ 98

    Change the last line with your path to the script and desired temperature, and don't forget to make the script executable too.

    Check if rc-local.service is running:

    # systemctl status rc-local.service

    Reboot and check if all went well by running again the above command, if all went well you should see something like this:

    # systemctl status rc-local.service
    rc-local.service - /etc/rc.d/rc.local Compatibility
    Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static)
    Active: activating (start) since Seg 2001-01-01 06:46:14 WET; 12 years 3 months ago
    Control: 1003 (rc.local)
    CGroup: name=systemd:/system/rc-local.service
    ├─ 1003 /bin/bash /etc/rc.d/rc.local start
    ├─ 1023 /bin/bash /root/ 98
    └─25269 sleep 3

  5. Great command. You can also use accurate temperature measurement devices and see how they work.

  6. Works great on Ubuntu 12.10. Thanks!

  7. I`ve got an error:

    $ sh 80 23: Syntax error: "(" unexpected
    ipeacocks@homepc:~/Downloads/cpu/temp-throttle-master$ bash 80
    Author: Sepero (sepero 111 @ gmail . com)
    Remote Python developer and Linux administrator for hire.

    Number of CPU cores detected: 4

    cat: /sys/class/thermal/thermal_zone0/temp: No such file or directory line 105: [: -gt: unary operator expected line 107: [: -le: unary operator expected

    1. Hi Ipeacocks, it doesn't run because you weren't using bash shell. I have made an update to the script so that it should now run with busybox shell also. Hopefully that helps. Cheers.

  8. This is fantastic. My ASUS laptop temp was breaking 80c running WINE, and now it doesn't top 65. When under load it stills runs a good 5-10c hotter than Windows 7, but it's much improved over the 10-20c difference I was seeing previously, both idling and under load. Thank you so much for this script!

  9. This is great!.. My HP laptop was always shutting down due to overheating. Now its stays below 80c often running at 75c while it usually run at 95-103c

  10. Hi Sepero I'm new in this, I run the script but I,ve git this error

    noelie@noelie-Aspire-5315:/tmp/temp-throttle-master$ sh 80
    Author: Sepero 2013 (sepero 111 @ gmx . com)

    -e Number of CPU cores detected: 1

    Error: Could not determine available cpu frequencies

    1. @madrisieraa, You have a technical problem that cannot be easily answered in the comment section of a blog. For further help, please contact me via email or on post an issue on Thank you

  11. Nice script. Very instructive. Actually took it only as a blueprint to throttle my CPU to a fixed max frequency. I have a Gaming Laptop with aggressive fan control. Throttling the CPU keeps the fan from speeding up during load peaks making it much more suitable for work related tasks (being still fast enough).

  12. Finally I fixed my laptop overheating problem with your script. I already was thinking of switching to windows. There are a lot of people struggling with overheating issue, just google "overheating linux" and you will see how many result will get back. We most share this script with the people who are struggling with this issue. THANKS ALOT Sepero

  13. thanks for sharing

    my laptop used to die when playing youtube videos for extended time, after showing kernel message like:

    CPU1: Core temperature above threshold, cpu clock throttled (total events = 131)

    I also think I found a method to choose which files to monitor: the computer halts when CPUs overheat, but which files do I have to watch to check for that?

    to discover it, run the following command in a terminal along with your favourite overheating application:

    while true; do sensors |grep Core; find /sys/devices/virtual/thermal/ -name temp|xargs -n1 grep -H .|grep -v :0; sleep 5;done

    my output is like:

    Core 0: +63.0°C (high = +80.0°C, crit = +90.0°C)
    Core 2: +61.0°C (high = +80.0°C, crit = +90.0°C)

    first lines are the CPU physical core(s) temperatures, other are temperature monitoring files

    observe it from some time as the temperature changes, and look for the files that follow the sensors output. for some reason probably some data fitlering, I never get an exact match, but I found out that in my case the sensors are thermal_zone7 and thermal_zone8. edit TEMPERATURE_FILES accordingly, leave only the core temperatures.

    you might also want to change the get_temp functions so that it finds the core max of core temperatures:

    get_temp () {
    # Get the system temperature.
    TEMP_i=$(cat $TEMP_FILE)
    if [ $TEMP_i -gt $TEMP ]; then

    1. HCE, it is difficult to discover the precise location of CPU temperature due to different machines reporting them differently. Some systems report very differently than what is common for most, and I would guess that your system falls in this category.

      You have suggested that I "edit TEMPERATURE_FILES accordingly, leave only the core temperatures". I understand that you suggest I edit the variable TEMPERATURE_FILES, but I'm not quite sure I understand how you think I should edit it. Perhaps you could give me an example of how you think it should look.

      Also, you suggest that the script should test for the highest temperature among all cores. On a normal system, all cores tend to stay within the same temperature range of each other. Though, I think you have an interesting idea for me to consider.

      Thank you for your great feedback

  14. What if I end the program while in the middle of the "throttle" ? the "unthrottle" will not happen thus my cpu freq will be lower and if the next throttle happens (by executing the program) it will be throttled DOUBLE TIME?

    1. If you end the program, your CPU will remain at the last state throttled. Your CPU will cannot be throttled "double time".

      If you want to restore your CPU to full throttle, stop the program and run it again with a very high temperature (like 150). After 10 seconds, you can end the program again.

  15. Hey this is cool, thanks! But, sometimes it allows the CPU to go beyond the set temp before throttling it back. I checked that with sensors while running the script. Do you have any idea why?

    1. The script checks for temperature updates every 3 seconds (this interval can be changed at the end of the script). When temperature has been exceeded, it will throttle down the CPU incrementally until a desirable temperature has been reached.

      If the CPU appears to be higher than expected, you may be reading from different temperature sensors than the script is reading from. Cheers

  16. I have a macbook air 2008, but it does not seem to be monitoring core tmp any help appreciated email

  17. Thank you, man. You have solved my problem. I was thinking in the purchase of a new laptop. Thanks again :)

  18. Hi,

    For me the script gives this error:

    robert@robert-desktop:~$ sudo ./ 80
    [sudo] password for robert:
    Author: Sepero 2016 (sepero 111 @ gmx . com)

    Number of CPU cores detected: 2

    Error: Could not determine available cpu frequencies

    Any idea what I can do?