Skip to content

Instantly share code, notes, and snippets.

View ChrisMacNaughton's full-sized avatar

Chris MacNaughton ChrisMacNaughton

View GitHub Profile
require 'absolute_time'
last_checked = 0.0
thread = Thread.new do
%x{ Shell command here }
end
while true
now = AbsoluteTime.now.to_f
if now.to_i > last_checked.to_i
File.open('some-file.txt', 'a') { |f| f.write(0)}
last_checked = now
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