在树莓派上使用C语言读取系统资源信息,包括CPU、内存、磁盘、网卡等,您可以通过读取特定文件或者调用系统命令来获取这些信息。以下是一个基本的示例,演示如何读取CPU温度、内存使用、磁盘空间以及网卡信息。
#include <stdio.h>
void readCPUTemperature() {
FILE *temperatureFile;
float cpuTemperature;
// 打开CPU温度文件
temperatureFile = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (temperatureFile == NULL) {
perror("Error opening temperature file");
return;
}
// 读取CPU温度
fscanf(temperatureFile, "%f", &cpuTemperature);
// 关闭文件
fclose(temperatureFile);
// 打印CPU温度
printf("CPU Temperature: %.2f°C\n", cpuTemperature / 1000.0);
}
void re