How can I get the current temperature of the CPU on Linux?
There are several questions and answers on getting the CPU temperature using C#, but all of them seem to be Windows specific.
If you know how to read a file in C# , and your computer is ACPI enabled, you may be able to read a file
/proc/acpi/thermal_zone/THRM/temperature
on other linux flavors it might be
/proc/acpi/thermal_zone/THM0/temperature
You would have to run this using mono on linux of course.
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"/proc/acpi/thermal_zone/THRM/temperature";
if (!File.Exists(path))
{
Console.WriteLine("Could not find "+path);
return;
}
string readText = File.ReadAllText(path);
Console.WriteLine(readText);
}
}
Without C#, you can use this command:
sudo sensors
Labels used in the output can be found in /etc/sensors3.conf
There is a way to use the in-built utilities to check the CPU temperature if you don’t want to use third-party apps.
To check the CPU temperature without installing a third-party app, use the following command:
cat /sys/class/thermal/thermal_zone*/temp
The output shows the CPU temperature in the five-digit format. For example, 49000 means 49C.
If you get several thermal zones and different temperatures, execute the following command to see what a single thermal zone represents:
Syntax: cat /sys/class/thermal/<thermal_zoneNumber>/type
For example, run cat /sys/class/thermal/thermal_zone0/type to see the type of thermal zone 0.
The CPU temperature is in the zone labeled x86_pkg_temp.
paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/(.)..$/.\1°C/'
The output shows the last stored temperature for that thermal zone in degrees Celsius. In this example, there is only one thermal zone, labeled x86_pkg_temp, which represents the CPU temperature.