有很多类似的问题,但我还没有找到解决方案。
如何在 Linux Ubuntu 12.10 上使用 C 或 C++ 获取 CPU 温度无需致电 sensors
?我当然可以从文件中读取它,但是我找不到它在 12.10 中的存储位置。简单地读取文本文件是唯一的可能性,还是我可以使用系统调用或信号查询内核?
我的文件夹 /proc/acpi/ 的内容只是
event wakeup
那里没有 THEMP0 或类似的东西。sensors
但是应用程序可以显示我的机器上的温度。
no /sys/class/thermal/thermal_zone0/
目录
in /sys/class/thermal
I have
cooling_device0@ cooling_device1@ cooling_device2@ cooling_device3@
我正在尝试浏览流明传感器 http://lm-sensors.org/browser寻找它如何检索温度的源代码,到目前为止还没有结果,但我已经很接近了。该文件是
http://lm-sensors.org/browser/lm-sensors/trunk/lib/sysfs.c 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)
根据系统文件系统文档 https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface,传感器信息存储在/sys/class/hwmon
每个芯片都有不同的目录。这与我在 Ubuntu 13.10 上看到的输出一致。
传感器使用的文件是:
/sys/class/hwmon/hwmon*/device/temp*
根据芯片/虚拟设备的数量,可以有很多hwmon
目录。
我的双核系统上的输出:
$ 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
Where hwmon1
是适合我的 CPU 的:
$ 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*
and temp3*
相当于core 0
and core 1
分别。基本上这些是文件sensors
从中读取数据。根据您拥有的硬件设备,您的 CPU 目录(hwmon1
就我而言)与温度信息可能会有所不同。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)