Mac OSX CPU Information. Terminal and Programmatically.

By | November 29, 2020

Apple Silicon CPU is coming. As announced x86_64 application will be able to run on ARM Apple Silicon using Rosetta translation, however there is some exclusion for example Rosetta doesn’t translate Kernel extensions. I checked this Saturday at Costco, they still sell Intel based Mac only.
I opened terminal on demo Macs and executed sysctl to get CPU information and I always got something like this:


$ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz

By the way it is possible to get the same CPU data programmaticaly. This is the code:


#include <stdio.h>
#include <sys/sysctl.h>
int main(int n, char ** s)
{
   char cpubrandstr[255];
   size_t len = 3;
   int mib[3];
   sysctlnametomib("machdep.cpu.brand_string", mib, &len);
   len = sizeof(cpubrandstr);
   int iError = sysctl(mib, 3, cpubrandstr, &len, NULL, 0);
   if(iError == 0)
   {
      printf("CPU Brand String: %s\n",cpubrandstr);
   } else {
      printf("Cannot get CPU Brand String. Error: %d\n", iError);
   }
   return 0;
}

So far I compiled my cpubrand_string.cpp code on x86_64 platform:


# g++ -mmacosx-version-min=10.11 -o cpubrand_string cpubrand_string.cpp
# ./cpubrand_string
CPU Brand String: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz

And I hope I can execute cpubrand_string on Apple Silicon as well due to Rosetta.

Leave a Reply

Your email address will not be published. Required fields are marked *