Class: Ps_ef

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = '') ⇒ Ps_ef

Returns a new instance of Ps_ef.



12
13
14
15
16
# File 'lib/Unix/Ps_ef.rb', line 12

def initialize(string = '')
  @table = {}

  decode(string) unless string.empty?
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



9
10
11
# File 'lib/Unix/Ps_ef.rb', line 9

def table
  @table
end

#zombiesObject (readonly)

Returns the value of attribute zombies.



10
11
12
# File 'lib/Unix/Ps_ef.rb', line 10

def zombies
  @zombies
end

Instance Method Details

#decode(string) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Unix/Ps_ef.rb', line 18

def decode(string)
  string.split("\n").each do |string|
    next if string =~ /UID\s+PID\s+PPID\s+C\s+STIME\s+TTY\s+TIME\s+CMD/

    process = Ps_process.new(string)
    @table[process.pid] = process
  end

  @table.each_key do |key|
    entry = @table[key]
    @table[entry.ppid].children += 1 unless entry.ppid == 0
  end
end

#have_more_children(number) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/Unix/Ps_ef.rb', line 32

def have_more_children(number)
  array = []

  @table.each_key do |key|
    next if @table[key].pid == 1 || @table[key].pid == 2
    array << @table[key].pid if @table[key].children > number
  end

  array
end