I have set up a dollar sign as shell prompt that shows the CPU temperature from sysfs sensor files in a color scale. In temperature-colored-bash-prompt- I put two screen shots. But the problem does not seem to be the prompt - the prompt only makes the (very) short peak visible in a drastic way.
I watched the temperature in one xterm with watch
and did different commands in another.
With ls -R /usr
xterm shows up in top
for 2 seconds (15%) and the temperature sensors react very nervous - so far so good.
With ls -R /usr >/dev/null
I get no reaction in top, the temperature can peak on one or more of the sensors shortly, and the colored prompt just reflects that.
I can get a green prompt three times in a row after ls -R /usr >/dev/null
, and then suddenly: hot pink for more than a second i.e. several quick enter taps. Same with find.
Do these short and very short peaks in sensor readings reflect any reality? How can a core go from 45 to 70 and back in one second (watch
) or shorter (prompt color)?
This is how it looks: the last part is the typical case: from green to red and back in two quick enter taps. Yesterday it was more getting stuck on magenta for a short while. Same effect on console.
The prompt:
PS1='$(systemp-color)$ \e[m'
and the function converting temperature to color sequence:
systemp-color() {
t=$(</sys/class/hwmon/hwmon2/temp1_input)
case $t in
3?000 ) c='1;34';;
4[012]000 ) c=36;;
4[345]000 ) c=32;;
4[6789]000 ) c='33';;
5?000 ) c='31';;
6?000 ) c='1;35';;
* ) c='30';;
esac
echo -ne "\e[${c}m"
}
Here the sensors:
$ cd /sys/class/hwmon/hwmon2/
$ grep "" temp?_label
temp1_label:Package id 0
temp2_label:Core 0
temp3_label:Core 1
temp4_label:Core 2
temp5_label:Core 3
$ grep "" temp?_input
temp1_input:43000
temp2_input:42000
temp3_input:42000
temp4_input:42000
temp5_input:41000