首页 > 其他 > 详细

获取CPU频率

时间:2014-05-02 14:21:44      阅读:553      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include <stdio.h>
#include <string.h>
float get_cpu_clock_speed()
{
    FILE *fp;
    char buffer[1024];
    size_t bytes_read;
    char *match;
    float clock_speed;
    fp=fopen("/proc/cpuinfo","r");
    bytes_read=fread(buffer,1,sizeof(buffer),fp);
    if(bytes_read==0 || bytes_read==sizeof(buffer))
        return 0;
    buffer[bytes_read]=\0;
    match=strstr(buffer,"cpu MHz");
    if(match == NULL)
        return 0;
    sscanf(match,"cpu MHz :%f",&clock_speed);
#if 0
    printf("buffer:%s, match:%s\n",buffer,match);#endif
    return clock_speed;
}
int main()
{
    printf("CPU clock speed:%4.0f MHz\n",get_cpu_clock_speed());
    return 0;
}
bubuko.com,布布扣

bubuko.com,布布扣

获取CPU频率,布布扣,bubuko.com

获取CPU频率

原文:http://www.cnblogs.com/lakeone/p/3703872.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!