Detects 64-bit processor in Ruby on Mac OS X

I want 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`

it gives 1

at will, but on a 32-bit processor, it gives an error message:

second level name cpu64bit_capable in hw.cpu64bit_capable is invalid

      

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

Thank.

+2


source to share


1 answer


You can use the command sysctl

by looking at the return value of the command.

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

      

On a 32 bit processor, it should return false

.




Alternatively, depending on what you're really looking for, you can test 64-bit EFI with ioreg

, although I think your processor might still be 64-bit with 32-bit EFI.

On a 64-bit EFI machine, you get this:

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

      

On a 64-bit EFI machine, you will get false

.

+4


source







All Articles