info cpu on osx with sysctl()

后端 未结 1 1685
夕颜
夕颜 2021-01-14 17:51

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

1条回答
  •  时光说笑
    2021-01-14 18:22

    I can do this on my iMac

    #include 
    #include 
    #include 
    
    #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);
    }
    

    and I get this

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

    0 讨论(0)
提交回复
热议问题