Skip to content

Instantly share code, notes, and snippets.

Created June 6, 2011 09:30
What would you like to do?
module System
extend self
def cpu_count
return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java
return'/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist? '/proc/cpuinfo'
require 'win32ole'
WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
rescue LoadError
Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1
System.cpu_count # => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment