Class: Soba::Services::ProcessInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/soba/services/process_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid) ⇒ ProcessInfo

Returns a new instance of ProcessInfo.



9
10
11
# File 'lib/soba/services/process_info.rb', line 9

def initialize(pid)
  @pid = pid.to_i
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/soba/services/process_info.rb', line 7

def pid
  @pid
end

Instance Method Details

#exists?Boolean

Returns:



29
30
31
32
33
34
35
36
# File 'lib/soba/services/process_info.rb', line 29

def exists?
  return false if pid <= 0

  Process.kill(0, pid)
  true
rescue Errno::ESRCH, Errno::EPERM
  false
end

#memory_usage_mbObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/soba/services/process_info.rb', line 13

def memory_usage_mb
  return nil unless exists?

  memory_kb = if File.exist?("/proc/#{pid}/status")
                # Linux: Read from /proc filesystem
                memory_from_proc
              else
                # macOS/other: Use ps command
                memory_from_ps
              end

  memory_kb ? (memory_kb / 1024.0).round(2) : nil
rescue StandardError
  nil
end