1、shell操作
cat /sys/class/thermal/thermal_zone0/temp
2、C语言文件IO操作
zw@ubuntu:~/Work/OpwnWrt_Src/Get_CPU_Temp$ cat Get_Temp.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp"
#define MAX_SIZE 32
double get_cpu_temp()
{
int fd;
double temp=-1;
char buf[MAX_SIZE];
fd = open(TEMP_PATH, O_RDONLY);
if (fd < 0)
{
fprintf(stderr, "failed to open thermal_zone0/temp\n");
return -1;
}
if (read(fd, buf, MAX_SIZE) < 0)
{
fprintf(stderr, "failed to read temp\n");
return -1;
}
temp = atoi(buf) / 1000.0;
close(fd);
return temp;
}
int main()
{
double temp=-1;
temp=get_cpu_temp();
if (-1!=temp)
{
printf("temp: %.2f\n", temp);
}
return 0;
}
zw@ubuntu:~/Work/OpwnWrt_Src/Get_CPU_Temp$