My desktop has a nasty habit. When I have several high intensity applications running and my CPU is at maximum usage for a period of time, the core temperature rises and my computer auto-shuts off.

Is there a way I can monitor (write a script) my CPU temperature in the background and have some sort of warning when it gets above a certain temperature?

I'm running Opensuse with dwm as my window manager. I usually use sensors to see my CPU temperature.

  • 1
    Under Linux, or some other unix variants? The method to obtain the temperature or be notified of temperature changes differs between unix variants. – Gilles 'SO- stop being evil' Nov 19 '11 at 23:22
  • My bad @Gilles, I added information to my question – n0pe Nov 19 '11 at 23:40
  • After you see that temperature rise you should throttle down your CPU. – Nils Nov 20 '11 at 21:07

You could write a script to display your temperature in dwm's status bar, for example:

temp (){
    awk '{print $4"°C"}' <(acpi -t)
    echo $temp
xsetroot -name "$(temp)"

Your sensors output may be more complex, depending on your setup: this works on one of my machines:

 awk '/temp1/ {print +$2"°C"}' <(sensors)

If you patch in statuscolours, you can additionally have the output change colour as the $temp hits higher values...

The Arch Wiki has an introduction to setting up a basic statusbar script and the dwm site includes an .xinitrc example.

You can see my dwm-status script for more details: http://beta.intuxication.org/jasonwryan/archer/file/tip/Scripts/dwm-status

  • This is a really great idea that I didn't think of. I never really had time to play around with dwm's statusbar so this will be fun. I'll see what I can manage and comment back. – n0pe Nov 20 '11 at 0:47
  • Worked perfectly, and now I have a nicely customized statusbar :) – n0pe Nov 20 '11 at 7:32
  • Excellent: it gives you quite a bit of scope to work with... – jasonwryan Nov 20 '11 at 7:52

I have exactly the same problem and what I use is the "cpufreqtools" (or just "cpufreq" - can't remember!) package.

It gives you two commands: cpufreq-info and cpufreq-set

cpufreq-info list the current CPU speed and the min and max speeds. and the available steps too.

cpufreq-set is more useful for you because you can limit the maximum speed that your CPU will ever reach.

My overheat-prone CPU has the available speeds of 800MHz, 1.60GHz and 1.80GHz. SO, what I do is limit it to 1.60GHz like this:

cpufreq-set --max 1.60Ghz

Works like a charm!

If you are more advanced in your Linux skills, you could even put it in a bootup script so it's always executed as soon as your Linux starts.

Good luck.

  • cpufrequtils (ubuntu 16.04). – Green Tree Jun 28 '17 at 7:28

I created a script to directly address this type of overheating problem. Limit your CPU based on a desired temperature. It runs automatically in the background like this:

sudo ./temp_throttle.sh 80

That command will make your CPU cores slow down when they reach 80 degrees Celsius. When the temperature goes down, the CPU cores will be allowed to run faster again. You can find temp_throttle here.

  • 1
    In the future, please do not expect everyone running Ubuntu with its default sudo-everything policy. Either mention that one has to allow the script in sudo configuration or (better) just write that it requires root privileges which may be achieved through sudo. Or - on Linux - describe the capabilities (as in the capabilities(7) man page) required. – peterph Jul 19 '14 at 7:57

There are 3 things I would recommend for dealing with this:

Chek your physical cooling

The CPU auto shutting down system is used in case of extreme situations in order to protect the CPU, when none of its internal temperature limiting strategies (see below) could work.

I would recommend checking your cooling system: removing dust from computer, checking if fans are operational, checking if heatsink is "big" enough with proper thermal paste (or pad), to ensure proper heat dissipation.

Configure your CPU internal temperature limit

CPUs usually have an internal temperature limiting system built-in, to avoid dangerous over heating. This protection usually makes use of performance-reducing (throttling) strategies like:

  • reducing CPU frequency,
  • reducing CPU voltage,
  • stopping CPU clock signal for brief periods.

On my laptop's Intel Core CPU, the maximum allowed temperature for auto-protection to start is 100°C (this is a pretty common hard limit). Intel also provides a configurable offset to lower this value even more. Having offset=8 results in a 92°C limit.

Since Linux 5.4, you can read and update Intel CPUs limit from sysfs with something like this:

# cd /sys/bus/pci/drivers/proc_thermal/0000:00:04.0
# cat tcc_offset_degree_celsius
# echo 8 >| tcc_offset_degree_celsius
# cat tcc_offset_degree_celsius

This would offer you extra over-heating protection and peace of mind within the CPU itself.

Use a system daemon (thermald) to manage CPU temperature

Another option is to use the thermald program, which main purpose is to monitor CPU temperature and take action to limit heating, from the OS side, before the hardware limits are hit.

It also uses techniques such as: ask CPU to limit its electrical power consumption (TDP limit), ask CPU to lower its p_state (frequency), changing kernel cpufreq parameters (i.e. asking it to use a power saving approach), inserting "CPU idle time" through specific a kernel driver, rising fan speed...

This page provides a good introduction to thermald.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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