freebsd下计算cpu、memory、hd等相信的代码

2009-05-13 06:54:09来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

/*
* 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) {

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:BSD系统的历史和目标(连载五)

下一篇:终于受不了瘸腿的crunchgen了