Method: LinuxStat::ProcessInfo.memory

Defined in:
lib/linux_stat/process_info.rb

.memory(pid = $$) ⇒ Object

memory(pid = $$)

Where pid is the process ID.

By default it is the id of the current process ($$)

It retuns the memory of the process. The value is in kilobytes.

The output is an Integer. For example:

LinuxStat::ProcessInfo.memory

8523.776

If the info isn’t available it will return nil.



147
148
149
150
151
152
153
# File 'lib/linux_stat/process_info.rb', line 147

def memory(pid = $$)
  file = "/proc/#{pid}/statm".freeze
  return nil unless File.readable?(file)

  data = IO.read(file).split
  (data[1] && data[2]) ? data[1].to_i.-(data[2].to_i).*(pagesize).fdiv(1000) : nil
end