Class: OsCtl::Cli::PidFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/cli/pid_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header: true) ⇒ PidFinder

Returns a new instance of PidFinder.



5
6
7
8
# File 'lib/osctl/cli/pid_finder.rb', line 5

def initialize(header: true)
  @finder = OsCtl::Lib::PidFinder.new
  print('PID', 'CONTAINER', 'CTPID', 'NAME') if header
end

Instance Attribute Details

#finderObject (readonly, protected)

Returns the value of attribute finder.



32
33
34
# File 'lib/osctl/cli/pid_finder.rb', line 32

def finder
  @finder
end

Instance Method Details

#find(pid) ⇒ Object

Parameters:

  • pid (Integer)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/osctl/cli/pid_finder.rb', line 11

def find(pid)
  ret = finder.find(pid.to_i)

  if ret.nil?
    print(pid, '-')

  elsif ret.ctid == :host
    print(pid, '[host]', '-', ret.os_process.name)

  else
    print(
      pid,
      "#{ret.pool}:#{ret.ctid}",
      ret.os_process.ct_pid,
      ret.os_process.name
    )
  end
end


34
35
36
# File 'lib/osctl/cli/pid_finder.rb', line 34

def print(pid, ct, ctpid = '-', name = '-')
  puts format('%-10s %-20s %-10s %s', pid.to_s, ct, ctpid.to_s, name)
end