I would like to check if my processor is AMD or INTEL in C and do necessary action according to that. What is the right and efficient way to get it in C?
Should i run system(linux command) or is there any other nice way to get it.
Join Stack Overflow to learn, share knowledge, and build your career.
I would like to check if my processor is AMD or INTEL in C and do necessary action according to that. What is the right and efficient way to get it in C?
Should i run system(linux command) or is there any other nice way to get it.
Since You didn't point an OS you are working at here is how you do it for OSX
#import <sys/sysctl.h>
I think that in c it is the same library just called by #include
To use uint64_t
type value you should include <stdint.h>
#include <sys/sysctl.h>
len=0;
uint64_t freq = 0; //
size_t size = sizeof(freq);
sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0);
if(len)
{
sysctlbyname("machdep.cpu.brand_string", &freq, &len, NULL, 0);
}
The answer you will get will be stored in freq
To know the name of sysctlbyname
you can run sysctl -a
in terminal
I think that sysctl
is also compatible with linux but I never test it on linux machine
*sizeof(char)
is never necessary, because sizeof(char)
is 1 by definition. Always.
– Fred Larson
Nov 11 '14 at 21:01