tags:

views:

529

answers:

1

I'm looking to differentiate between Core Solo/Duo and Core 2 Duo processors for 64-bit support.

On a Core 2 Duo, then `sysctl hw.cpu64bit_capable` gives 1, as desired, but on a 32-bit processor, it throws an error, saying:

second level name cpu64bit_capable in hw.cpu64bit_capable is invalid

What's the best way to detect a 64-bit processor?

Thanks.

+1  A: 

You can still use your sysctl command by looking at the command's return value.

$ irb
>> system("sysctl hw.cpu64bit_capable > /dev/null 2>&1")
=> true

On 32 bit CPU it should return false.


Alternatively, depending what you're really looking for, you can test for 64 bit EFI with ioreg, though I think your CPU could still be 64 bit with a 32 bit EFI.

On a 64 bit EFI machine, you'd get this:

$ irb
>> system("ioreg -l -p IODeviceTree | grep firmware-abi | grep -q EFI64")
=> true

On a machine lacking 64 bit EFI, you'd get false.

Ryan McGeary