Chinaunix首页 | 论坛 | 博客
  • 博客访问: 695230
  • 博文数量: 160
  • 博客积分: 8847
  • 博客等级: 中将
  • 技术积分: 1656
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-25 16:46
个人简介

。。。。。。。。。。。。。。。。。。。。。。

文章分类

全部博文(160)

文章存档

2015年(1)

2013年(1)

2012年(4)

2011年(26)

2010年(14)

2009年(36)

2008年(38)

2007年(39)

2006年(1)

分类: BSD

2007-02-09 15:07:23

/*
 * FreeBSD CPU Information 0.1
 * ---------------------------
 * Simple program to display the total RAM, and CPU information.
 * Compile: cc -o cpuinfo cpuinfo.c
 * ---------------------------
 */

#include
#include
#include
#include
#include
#include

extern int errno;

int main(void)
{
        int len, numcpu, cpuspeed, totalmem, usermem;
        char cpuarch[64], cpumodel[64];

        printf("FreeBSD CPU Information\n");
        printf("Version 0.1\n");

        len = sizeof(cpuarch);
        if (sysctlbyname("hw.machine_arch", &cpuarch, &len, NULL, NULL) == -1)
{
                perror("sysctlbyname()");
                return -1;
        }

        len = sizeof(cpumodel);
        if (sysctlbyname("hw.model", &cpumodel, &len, NULL, NULL) == -1) {
                perror("sysctlbyname()");
                return -1;
        }

        len = sizeof(cpuspeed);
        if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &len, NULL, NULL) ==
-1) {
                perror("sysctlbyname()");
                return -1;
        }

        len = sizeof(numcpu);
        if (sysctlbyname("hw.ncpu", &numcpu, &len, NULL, NULL) == -1) {
                perror("sysctlbyname()");
                return -1;
        }

        len = sizeof(totalmem);
        if (sysctlbyname("hw.physmem", &totalmem, &len, NULL, NULL) == -1) {
                perror("sysctlbyname()");
                return -1;
        }

        len = sizeof(usermem);
        if (sysctlbyname("hw.usermem", &usermem, &len, NULL, NULL) == -1) {
                perror("sysctlbyname()");
                return -1;
        }

        cpuspeed = cpuspeed / 1000000;
        totalmem = (totalmem - 1000000) / 1000000;
        usermem = (usermem - 1000000) / 1000000;

        printf("Architecture:\t%s\n", cpuarch);
        printf("Number of CPUs:\t%d\n", numcpu);
        printf("CPU Model:\t%s\n", cpumodel);
        printf("CPU Speed:\t%dMHz\n", cpuspeed);
        printf("Total Memory:\t%dMB\n", totalmem);
        printf("User Memory:\t%dMB\n", usermem);
        printf("\n");

        return 0;
}


阅读(2267) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~