Module: ForkAndReturn::Util

Defined in:
lib/forkandreturn/util.rb

Overview

:nodoc: Stuff copied from my personal library.

Class Method Summary collapse

Class Method Details

.coresObject



7
8
9
# File 'lib/forkandreturn/util.rb', line 7

def self.cores
  @cores	||= (l = cpu_info.length) < 1 ? 1 : l
end

.cpu_infoObject

TODO: Might not be correct, but it works for now.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/forkandreturn/util.rb', line 11

def self.cpu_info	# TODO: Might not be correct, but it works for now.
  @cpu_info ||=
  begin
    cpus	= []

    if File.file?("/proc/cpuinfo")
      File.open("/proc/cpuinfo") do |f|
        while line = f.gets
          key, value	= line.chomp.split(/\s*:\s*/, 2)

          if key and value
            cpus << {}	if key == "processor"

            cpus[-1][key]	= value
          end
        end
      end
    end

    cpus
  end
end

.forkable?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/forkandreturn/util.rb', line 34

def self.forkable?
  @forkable ||=
  begin
    Process.wait(
      Process.fork do
        Process.exit!
      end
    )

    true
  rescue NotImplementedError
    false
  end
end

.multi_core?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/forkandreturn/util.rb', line 3

def self.multi_core?
  @multi_core	||= cores > 1
end