John Ten Cate John Ten Cate - 1 month ago 13
Objective-C Question

How to determine kernel bitness in Mac OS X 10.6?

I know that I can use the terminal and the system-profiler command to determine the current bitness of the kernel but I am trying to determine if there is a way to get that same information programmatically in objective-c.

I have looked through Carbon's gestalt, but haven't seen anything that would tell me bitness of the kernel.

Does anyone have any suggestions as to how I could do this? I need this info for a debugging report that gives a snapshot of the system at the time of the report.

Thanks!

Update: One thing I have tried that is a trick I learned from the Windows world is to check the size of an int like:

sizeof(int*); //(4 = x86 8 = x64)


but I don't think this is a resolution because I think this will only give me an idea of what the actual program itself is running at and not the actual OS kernel. My understanding is that even though the OS kernel is running at 32 bit your program can still run at 64bit.

I have run across other forum posting similar to this one but none of them seem to come up with an answer other then using system_profiler.

Answer

See man 3 uname: It fills a utsname structure which includes a member machine, which is "x86_64" or "i386" on Intel platforms:

struct utsname un;
int res = uname(&un);
if (res >= 0) {
    NSLog(@"%s", un.machine);
}
Comments