简体   繁体   中英

detect 64-bit CPU in Ruby on Mac OS X

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM