class Object

Public Instance Methods

num_cpus() click to toggle source

Return the number of CPU cores (should work on Unixy platforms)

# File lib/anschel.rb, line 6
def num_cpus
  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'
  return `sysctl -a | grep cpu`.split(/\s+/,2).last.to_i
rescue
  return 2
end