linux cpu 温度 代码,linux CPU温度

在Linux系统中,CPU温度可通过阅读`/sys/class/thermal`目录下的相关文件来获取。`x86_pkg_temp`标识的是CPU温度。本文提供了一段Python代码,用于读取并返回所有匹配`x86_pkg_temp`类型的CPU温度。
摘要由CSDN通过智能技术生成

linux下一切皆文件,那么`CPU温度`的描述文件保存在哪呢?

要查看`有关温度`的东西,我们可以去`/sys/class/thermal`下查找:

```bash

~# ls

cooling_device0 cooling_device2 cooling_device4 cooling_device6 cooling_device8 thermal_zone0 thermal_zone2

cooling_device1 cooling_device3 cooling_device5 cooling_device7 cooling_device9 thermal_zone1

```

那么,这里哪个是描述`CPU`的温度呢?答案是包含在`thermal_zone*/temp`中,那么到底是哪个呢?我们先看下`thermal_zone*/type`这个文件:

```bash

~# cat thermal_zone0/type thermal_zone2/type thermal_zone2/type

acpitz

acpitz

x86_pkg_temp

```

看出区别了?没错,就是`x86_pkg_temp`。所以,要获得`CPU温度`,需要先查看`/sys/class/thermal/thermal_zone*/type`文件是否为`x86_pkg_temp`,然后在查看相应的`/sys/clas

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值