The lm-sensors project (and therefore the sensors
command) makes use of the libsensor library; the libraries and package are:
Ubuntu 18.04: libsensors4, version 3.4.0-4
sudo apt install libsensors4
Ubuntu 20.04: libsensors5, version 3.6.0.
sudo apt install libsensors5
I also recommend to install the developer package (includes man pages), which is the same for LTS 18.04 and LTS 20.04:
sudo apt install libsensors4-dev
Some background information can no be found on:
man libsensors
man sensors.conf
BTW this is the same library which reads the temperature as seen in the sys
directory.
To sum it up, sensors is a good choice. Watching the temperature from command-line can be easily done by
watch -n 1 sensors
If you intend to write a program, take a look at the libsensors manual man libsensors
or make use of your /usr/share/doc/
documentation. In a C-program you have to include #include <sensors/sensors.h>
headers. It will use the sensors.conf
files /etc/sensors3.conf and/or /etc/sensors.conf. Further (users) configuration can be found in /etc/sensors.d/
, if you make use of this option.
If you think that you are missing some sensors take a look at the /sys/class/thermal
or the linked /sys/devices/virtual/thermal
directory.
To get the temperatures of the all thermal zones use the command
$ cat /sys/devices/virtual/thermal/thermal_zone?/temp
77000
66000
67000
The temperature is measured in miliCelcius (mC), in the case above, the temperature measured in celsius are: 77.0, 66.0, 67.0 °C.
To watch the temperatures continuously use
watch -n 1 cat /sys/devices/virtual/thermal/thermal_zone?/temp
In this directory you can also find information about your cooling (fan) devices, and how the PID regulators are programmed.
Further some over-temperature protection is coded firmware/hardware based (this is a good idea), and its set-up data is placed in your bios.
If you prefer to display the temperature in °C instead of °mC use the bash computation $((value / 1000 ))
or awk to make this conversion:
cat /sys/devices/virtual/thermal/thermal_zone?/temp | awk '{printf " %5.2f °C\n" , $1/1000}'