码迷,mamicode.com
首页 > 其他好文 > 详细

获取CPU频率

时间:2014-05-02 14:20:39      阅读:392      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   javascript   

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频率

标签:style   blog   class   code   java   javascript   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!