使用AMD FX 4100四核在linux ubuntu 12.10上获取CPU温度 [英] get CPU temperature on linux ubuntu 12.10 with AMD FX 4100 Quad Core

查看:118
本文介绍了使用AMD FX 4100四核在linux ubuntu 12.10上获取CPU温度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多与此类似的问题,但是我还没有找到解决方法.

There are many questions similar to this but I haven't found solution there.

如何在Linux Ubuntu 12.10上的C或C ++中获得CPU温度而无需调用 sensors ?我当然可以从文件中读取它,但是我找不到它在12.10中的存储位置.并且仅仅是读取文本文件的可能性而已吗?或者我可以使用系统调用或信号查询内核吗?

How can I get CPU temperature in C or C++ on Linux Ubuntu 12.10 without call to sensors? I can of course just read it from file, however I cannot find where it is stored in 12.10. And is simple reading a text file only possibility or maybe I can query the kernel using system call or signal?

我的文件夹/p​​roc/acpi/的内容仅仅是

Content of my folder /proc/acpi/ is just

event  wakeup

那里没有THEMP0或类似的东西.但是, sensors 应用程序可以在我的机器上显示温度.

No THEMP0 there or anything like this. sensors application however can display a temperature on my machine.

没有/sys/class/thermal/thermal_zone0/目录

我在/sys/class/thermal

cooling_device0@  cooling_device1@  cooling_device2@  cooling_device3@

我正在尝试浏览 lm-sensors 源代码,以寻找如何获取温度的方法,到目前为止无济于事,但是我很近.该文件是

I'm trying to browse lm-sensors source code in search for how it retrieves temperature, to no avail so far, however I am close. The file is

http://lm-sensors.org/browser/lm-sensors/trunk/lib/sysfs.c

尤其是:

第846行:

846 int sensors_read_sysfs_attr(const sensors_chip_name *name,
847                             const sensors_subfeature *subfeature,
848                             double *value)

推荐答案

根据 sysfs文档,传感器信息存储在/sys/class/hwmon 下,每个芯片的目录不同.这与我在Ubuntu 13.10上看到的输出一致.

According to the sysfs documentation, the sensors information is stored under /sys/class/hwmon with different directory for each chip. Which is consistent with the outputs I see on my Ubuntu 13.10.

传感器使用的文件为:

/sys/class/hwmon/hwmon*/device/temp*

根据芯片/虚拟设备的数量,可能会有许多 hwmon 目录.

Depending on the number chips/virtual devices, there can be many hwmon directories.

双核系统上的输出:

$ pwd
/sys/class/hwmon
$ ls -l
total 0
lrwxrwxrwx 1 root root 0 May 17 14:29 hwmon0 -> ../../devices/virtual/hwmon/hwmon0
lrwxrwxrwx 1 root root 0 May 17 14:29 hwmon1 -> ../../devices/platform/coretemp.0/hwmon/hwmon1
lrwxrwxrwx 1 root root 0 May 17 14:29 hwmon2 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/hwmon/hwmon2

其中 hwmon1 是适合我的CPU的位置:

Where hwmon1 is the one for my CPUs:

$ pwd
/sys/class/hwmon/hwmon1/device
$ ls -l
total 0
lrwxrwxrwx 1 root root    0 May 17 14:29 driver -> ../../../bus/platform/drivers/coretemp
drwxr-xr-x 3 root root    0 May 17 14:29 hwmon
-r--r--r-- 1 root root 4096 May 17 23:21 modalias
-r--r--r-- 1 root root 4096 May 17 14:29 name
drwxr-xr-x 2 root root    0 May 17 23:21 power
lrwxrwxrwx 1 root root    0 May 17 14:29 subsystem -> ../../../bus/platform
-r--r--r-- 1 root root 4096 May 17 14:29 temp2_crit
-r--r--r-- 1 root root 4096 May 17 14:29 temp2_crit_alarm
-r--r--r-- 1 root root 4096 May 17 14:29 temp2_input
-r--r--r-- 1 root root 4096 May 17 23:11 temp2_label
-r--r--r-- 1 root root 4096 May 17 14:29 temp2_max
-r--r--r-- 1 root root 4096 May 17 14:29 temp3_crit
-r--r--r-- 1 root root 4096 May 17 14:29 temp3_crit_alarm
-r--r--r-- 1 root root 4096 May 17 14:29 temp3_input
-r--r--r-- 1 root root 4096 May 17 23:11 temp3_label
-r--r--r-- 1 root root 4096 May 17 14:29 temp3_max
-rw-r--r-- 1 root root 4096 May 17 14:29 uevent

temp2 * temp3 * 中的值分别对应于 core 0 core 1 .基本上,这些是文件 sensors 从中读取数据.根据您所拥有的硬件设备,带有温度信息的CPU目录(在本例中为 hwmon1 )可能会有所不同.

The values from temp2* and temp3* correspond to core 0 and core 1 respectively. Basically these are the files sensors read data from. Depending on your hardware devices you have, your CPU directory (hwmon1 in my case) with temperature information may be different.

这篇关于使用AMD FX 4100四核在linux ubuntu 12.10上获取CPU温度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆