Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm temporarily forced to work on a laptop whose fan has failed. Under light load it works fine, but as soon as I start computationally intensive jobs, the temperature raises very significantly, even when the cpufreq is pegged to the minimum.

I'd like to automate something i'm doing by hand for now, suspending the expensive job with Ctrl-Z when the temperature raises above some threshold, and resume it when the temperature drops below a certain point.

Is there an existing command or wrapper script that does that, before I write my own ?

Running a single job under a wrapper would be enough, but it would be nicer if it could suspend a whole class of tasks; unfortunately I cannot easily run all my expensive jobs under some user, but I could renice them, and suspend all the niced jobs when it overheats.

share|improve this question
    
Should be possible, but I have never seen anything that does this on any platform –  soandos Aug 2 '12 at 23:05
    
I wrote a small bash script using sensors to do that: github.com/B2F/hotprocessensors –  ZenMaster Jun 7 '13 at 19:25

2 Answers 2

I suppose you currently check CPU temperature with sensors of some other command line utility?

In that case you could write a small script which constantly (thus with an interval of, say, 2 seconds) checks this output.

This could be done in php using the following script:

<?php

$threshold = 78;  //The value at which you will start killing processes
$processes = array(  //All the processes to be killed when threshold is reached
    'sampleprocess',
    'anotherveryintensiveprocess',
);

while (true)
{
    exec('sensors', $output);

    $temperature = 0;
    $div = 0;
    foreach ($output as $line)
    {
        preg_match('@\\+[0-9]+\\.[0-9]°C@', $line, $match);
        if (count($match) <> 1) continue;
        $temperature+= substr($match[0], 1, -2);
        $div++;
    }

    if ($div == 0)
        exit;

    $temperature/= $div;

    if ($temperature >= $threshold)
    foreach ($processes as $proc)
        passthru("killall -9 \"$proc\""); //You can also forget about the `-9`

    sleep(2);    //polling interval
}

?>

Note that this script expects output form sensors in a form where the first sequence of +<number>.<number>°C represents the temperature. For this output it thus works as expected:

coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +40.0°C  (high = +78.0°C, crit = +100.0°C)
Core 1:       +38.0°C  (high = +78.0°C, crit = +100.0°C)

The -9 in the killall command isn't strictly required, it is just there to send SIGKILL, instead of SIGTERM. To send other signals (like SIGUSR1) you can try killall -SIGUSR1.

Hope it helps.

share|improve this answer

You might try/adapt Keep cool.

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.