I need to run a specific command if my laptop gets too hot (for example, send a STOP signal to Firefox or Virtualbox in order to prevent my laptop from shutting down violently and damaging my hard disks).

I can easily write a program that loops indefinitely while periodically checking the temperature. This question's answer uses this approach.

However, I would like to avoid running my own daemon and instead attach my program to an existing one. For example, I can see in my syslog:

May 5 02:52:27 myhostname kernel: [ 9141.022262] intel ips 0000:00:1f.6: MCP limit exceeded: Avg temp 9276, limit 9000

So there is already code in my machine checking for temperature, which fires some action depending on a condition (eg log warning message when temperature exceeds 9000). Another example is that the fan speeds up based on the same temperature.

How can I attach my program to this existing code in my machine? Are the fan driver speed change and kernel temperature warning message fired from the same code? How can I find this out?

4 Answers 4


You're going to have to run some sort of daemon that monitors for that sort of thing. Hardware sensors are just inert data sources and usually can't actually perform actions on their own.

If you're just looking to get out out writing custom code, you can look into installing the collectd-sensors package (your distro may call it something else) which will keep a history of temperatures. After you configure collectd to track temperature data you should be able to set up a collectd notification for that kind of event.

  • I'm not trying to "get out of writing custom code", I want to insert my custom code into some place that is already firing events for what I need. And I don't think I suggested that the hardware sensor itself needs to fire an action. However, there is already code in my system which is polling for the data of the sensors.
    – user84207
    May 5, 2014 at 19:12
  • For example, there exists some code in my machine that makes the fan run faster when temperature reaches a certain value. There is some other code which prints MCP limit exceeded to the syslog. These processes are already polling the same underlying device, and I don't want to introduce yet another poller.
    – user84207
    May 5, 2014 at 19:17
  • The MCP limit exceeded is coming from the kernel, which only fires off syslog messages, it doesn't have any framework for executing arbitrary commands that I'm aware of. That's why I suggested configuring lm_sensors to interface with the temperature sensors (which is reference in the answer you were looking at originally). My answer states you can configure collectd to keep a history (probably useful anyways) and that collectd can be configured via the EXEC plugin to execute arbitrary scripts when certain thresholds are reached.
    – Bratchley
    May 5, 2014 at 21:02
  • Beyond that, I don't really see why the other answer (in your linked question) wouldn't work for you either. Just run that script in the background and it ought to check these readings for you. You'd just have to modify the script to send the SIGSTP and SIGCONT signals you're apparently wanting to have happen.
    – Bratchley
    May 5, 2014 at 21:07

How can I attach my program to this code?

That particular output is from the kernel, so you might be able to write a kernel module for this, or if the information is not globally accessible, a patch to an existing one.

WRT daemons you already have running, you could make use of cron and check this every minute or so.

If you want a granularity finer than minutes, you'll need to either write your own loop, or find a tool that does this already -- some GUI system monitors may allow you to configure alarms which can run an arbitrary process (I notice gkrellm does not, and it is hard to tell just by googling about conky).

  • this is exactly my problem: I want very high granularity, but I don't want to create a cpu-intensive process just to check the temperature. This is why I'd like to hook my program to existing code.
    – user84207
    May 5, 2014 at 19:31
  • any pointers about how to write a kernel module or perhaps modify the one that causes the "MCP limit exceeded" syslog message?
    – user84207
    May 6, 2014 at 0:27
  • WRT the kernel you'd probably have to go the patch route, which makes it more complicated -- you have to figure out what you are patching. WRT a "cpu intensive process"; something which sleeps for 5-10 seconds then checks one node in /proc (the core temp) is not cpu intensive. Even on a small system it will report a fraction of a percent cpu usage over time, on a modern desktop it won't amount to anything at all.
    – goldilocks
    May 6, 2014 at 13:43

Seems like a DBUS or ACPI event would be a place to latch onto these "events" and fire a command to do what you want. I show a method for doing this using dbus-monitor which could be adapted to "catch" these events and then run your script.

Take a look at my answer to this U&L Q&A titled: Can libnotify be used to execute a script?

  • how would I use DBUS to listen to temperature-related events?
    – user84207
    May 6, 2014 at 0:25

This requires that you are willing to have the trigger for your Firefox/Virtualbox be the same temperature that triggers the message to your logs and are also willing to run syslog-ng.

syslog-ng can be configured to run arbitrary code triggered by a message being sent to the log, from a particular program or with particular contents.

In your syslog-ng.conf you would add a new destination:

destination d_high_temp { program("/path/to/OPs/temperature_script"); };

and also a new filter to go with

filter f_high_temp { match("MCP limit exceeded" value("MESSAGE")); };

and lastly

log { source(src); filter(f_high_temp); destination(d_high_temp); };

You'll be running no more daemons than you already are but will still be able to shutdown whatever programs you like.

  • this answer looks like it is closer to what I was asking, although it is a bit restrictive about the condiions which cause a trigger. But obviously the kernel code which generates these messages is frequently polling the temperature. I wonder if I could hack apart whatever code is responsible for the message itself
    – user84207
    May 6, 2014 at 0:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .