2

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.

Community
  • 1
  • 1
arastoo.s
  • 51
  • 1
  • 3

3 Answers3

6

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);
    }
}
Anders Forsgren
  • 10,827
  • 4
  • 40
  • 77
1

Without C#, you can use this command:

sudo sensors

Labels used in the output can be found in /etc/sensors3.conf

BuzzRage
  • 184
  • 1
  • 12
1

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.

  1. 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.

  1. 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.

  1. To see what all the thermal zones are referring to, use:

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.