Detect number of CPUs installed

前端 未结 12 921
孤城傲影
孤城傲影 2020-12-24 05:29

I already found a solution for \"Most unixes\" via cat /proc/cpuinfo, but a pure-Ruby solution would be nicer.

12条回答
  •  失恋的感觉
    2020-12-24 06:06

    Combination of @grosser's and @paxdiablo's answer, since on my system (winxp) win32_computersystem doesn't have any processor info; this works though:

    require 'win32ole'
    wmi = WIN32OLE.connect("winmgmts://")
    info = wmi.ExecQuery ("select NumberOfCores from Win32_processor")
    puts info.to_enum.first.NumberOfCores
    

    To see what's available on your system, run this from powershell (i used 1.0 in this case):

    Get-WmiObject -list
    

    (might want to pipe to grep if you've got cygwin installed)

提交回复
热议问题