使用sysctl()在osx上使用信息cpu [英] info cpu on osx with sysctl()

查看:132
本文介绍了使用sysctl()在osx上使用信息cpu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在osx上工作,我想获得有关我的CPU的一些信息.为此,我找到了终端命令sysctl -a,但是我需要在程序中获取这些信息,因此需要使用systcl()函数.

I am working on osx and i would like to get some info about my cpu. To do that, i found the terminal commande sysctl -a, but i need to get these informations in a programme so i need to use the function systcl();

我试图读那个人,但我仍然不知道如何获取一个字符串,例如我的cpu名称(例如终端命令sysctl machdep.cpu.brand_string)

i tried to read the man but i still have no idea how to get a string with for example the name of my cpu (like the terminal commande sysctl machdep.cpu.brand_string)

好吧,我很高兴收到任何提示,帮助或示例:D

well i would be very happy for any hint, help or example :D

推荐答案

我可以在我的iMac上完成此操作

I can do this on my iMac

#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>

#define BUFFERLEN 128

int main(){
    char buffer[BUFFERLEN];
    size_t bufferlen = BUFFERLEN;
    sysctlbyname("machdep.cpu.brand_string",&buffer,&bufferlen,NULL,0);
    printf("%s\n", buffer);
}

我明白了

Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz

这篇关于使用sysctl()在osx上使用信息cpu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆