procinfo.cpp

来自「这是linux下读取pc主板温度传感器的源代码」· C++ 代码 · 共 81 行

CPP
81
字号
/***************************************************************************                          procinfo.c  -  description                             -------------------    begin                : Wed Jan 9 2002    copyright            : (C) 2002 by Miguel Novas    email                : michaell@teleline.es ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include "procinfo.h"#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <string.h>#include <sys/stat.h>bool existsFile(const char *file){struct stat buf; return (stat((const char *)file,&buf)==0);}int read_file(const char *name, char *buf, int max){    int fd = open(name, O_RDONLY);    if(fd >= 0) {       int r = read(fd, buf, max);       close(fd);       return r;    }    return -1;}// ***** Dell i8k sensors info *****////    $ cat /proc/i8k//    1.0 A17 2J59L02 52 2 1 8040 6420 1 2////The fields read from /proc/18k are:////    1.0 A17 2J59L02 52 2 1 8040 6420 1 2//    |   |   |       |  | | |    |    | |//    |   |   |       |  | | |    |    | +------- 10. buttons status//    |   |   |       |  | | |    |    +--------- 9.  ac status//    |   |   |       |  | | |    +-------------- 8.  right fan rpm//    |   |   |       |  | | +------------------- 7.  left fan rpm//    |   |   |       |  | +--------------------- 6.  right fan status//    |   |   |       |  +----------------------- 5.  left fan status//    |   |   |       +-------------------------- 4.  CPU temperature (Celsius)//    |   |   +---------------------------------- 3.  serial number//    |   +-------------------------------------- 2.  BIOS version//    +------------------------------------------ 1.  /proc/i8k format versionint getI8KInfo(double *cpuTemp,  double *leftFan, double *rightFan){double version;char buf[256]; if(read_file("/proc/i8k", buf, sizeof(buf)) <= 0) return -1; if(sscanf(buf, "%lf %*s %*s %lf %*d %*d %lf %lf", &version, cpuTemp,leftFan,rightFan)!=4) return -2; if(version!=1.0) return -3; return 0;}// *************  Acpi temperature ************// cat /proc/acpi/thermal_zone/THRM/temperature// temperature: 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?