Created
June 6, 2011 09:30
-
-
Save rkh/1009994 to your computer and use it in GitHub Desktop.
Revisions
-
rkh created this gist
Jun 6, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ module System extend self def cpu_count return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java return File.read('/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 end end System.cpu_count # => 2