Class: MemInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/mem_info.rb

Instance Method Summary collapse

Instance Method Details

#mem_totalObject

Total memory in kb. On Mac OS uses “sysctl”, elsewhere expects the system has /proc/meminfo. Returns nil if it cannot be determined.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mem_info.rb', line 6

def mem_total
  @mem_total ||=
    begin
      system = `uname`.strip
      if system == "Darwin"
        s = `sysctl -n hw.memsize`.strip
        s.to_i / 1.kilobyte
      else
        s = `grep MemTotal /proc/meminfo`
        /(\d+)/.match(s)[0].try(:to_i)
      end
    rescue StandardError
      nil
    end
end