如何在Linux上获得CPU的温度

时间:2012-02-25 12:57:18

标签: c# linux mono

如何在Linux上获取CPU的当前温度?

使用C#获取CPU温度有several questions and answers,但所有这些似乎都是Windows特定的。

2 个答案:

答案 0 :(得分:6)

如果您知道如何在C#中读取文件,并且您的计算机已启用ACPI,则可能能够读取文件

 /proc/acpi/thermal_zone/THRM/temperature

在其他Linux风格上可能是

 /proc/acpi/thermal_zone/THM0/temperature

你必须在linux上使用mono运行它。

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);
    }
}

答案 1 :(得分:-1)

没有C#,您可以使用此命令:

sudo sensors

输出中使用的标签可以在/etc/sensors3.conf

中找到