Class: HawatelPS::Windows::ProcTable

Inherits:
Object
  • Object
show all
Defined in:
lib/hawatel_ps/windows/proc_table.rb

Class Method Summary collapse

Class Method Details

.childs_treeObject (private)

Get process childs



125
126
127
128
129
130
131
132
133
# File 'lib/hawatel_ps/windows/proc_table.rb', line 125

def childs_tree
  @proc_table.each do |proc_parent|
    @proc_table.each do |proc_child|
      if proc_parent.processid === proc_child.parentprocessid
        proc_parent[:childs].push(proc_child)
      end
    end
  end
end

.find_allObject (private)

Refresh processes array



116
117
118
119
120
121
122
# File 'lib/hawatel_ps/windows/proc_table.rb', line 116

def find_all
  @proc_table = Array.new
  ProcFetch.get_process.each do |proc_attrs|
    @proc_table.push(ProcInfo.new(proc_attrs))
  end
  childs_tree
end

.find_by_name(name) ⇒ Object (private)

Refresh processes array by name



107
108
109
110
111
112
113
# File 'lib/hawatel_ps/windows/proc_table.rb', line 107

def find_by_name(name)
  @proc_table = Array.new
  ProcFetch.get_process({:name => name}).each do |proc_attrs|
    @proc_table.push(ProcInfo.new(proc_attrs))
  end
  childs_tree
end

.find_by_pid(pid) ⇒ Object (private)

Refresh processes array by pid



98
99
100
101
102
103
104
# File 'lib/hawatel_ps/windows/proc_table.rb', line 98

def find_by_pid(pid)
  @proc_table = Array.new
  ProcFetch.get_process(:processid => pid).each do |proc_attrs|
    @proc_table.push(ProcInfo.new(proc_attrs))
  end
  childs_tree
end

.proc_tableArray<ProcInfo>

Return all process instances

Returns:



91
92
93
94
# File 'lib/hawatel_ps/windows/proc_table.rb', line 91

def proc_table
  find_all
  return @proc_table
end

.search_by_condition(args) ⇒ Array<ProcInfo>

Return attributes of searched by process

Examples:

search_by_condition(:attrs => 'workingsetsize', :oper => '<', value => '10000')

Parameters:

  • args (Hash)

    attributes for search condition @attrs [String], name of process attribute (first expression for if) @oper [String], operatator, available options: >,<,>=,<=,==,!= @value [String], value comparable (second expression for if)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/hawatel_ps/windows/proc_table.rb', line 61

def search_by_condition(args)
  find_all

  attrs = args[:attr]
  oper  = args[:oper]
  value = args[:value]
  process_list = Array.new
  @proc_table.each do |process|
    if oper == '>'
      process_list << process if process[:"#{attrs}"] > value
    elsif oper == '<'
      process_list << process if process[:"#{attrs}"] < value
    elsif oper == '>='
      process_list << process if process[:"#{attrs}"] >= value
    elsif oper == '<='
      process_list << process if process[:"#{attrs}"] <= value
    elsif oper == '=='
      process_list << process if process[:"#{attrs}"] == value
    elsif oper == '!='
      process_list << process if process[:"#{attrs}"] != value
    end
  end

  process_list = nil if process_list.empty?

  return process_list
end

.search_by_name(process_name) ⇒ Array<ProcInfo>

Return attributes of searched process based on name or cmdline

Examples:

search_by_name('java.exe')
search_by_name('/^regex/')

Parameters:

  • process_name (String)

    name of process

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hawatel_ps/windows/proc_table.rb', line 26

def search_by_name(process_name)
  if process_name =~ /^\/.*\/$/
    process_name.slice!(0)
    process_name = Regexp.new(/#{process_name.chop}/)
    find_all
  else
    find_by_name(process_name)
  end

  process_list = Array.new

  @proc_table.each do |process|
    if process_name.is_a? Regexp
      process_list << process if process.name =~ process_name || process.commandline =~ process_name
    else
      process_list << process if process.name.to_s.downcase == "#{process_name.to_s.downcase}" || process.commandline.to_s.downcase == "#{process_name.to_s.downcase}"
    end
  end

  process_list = nil if process_list.empty?

  return process_list
end

.search_by_pid(pid) ⇒ ProcInfo

Return attributes of searched process based on pid

Examples:

search_by_pid(1761)

Parameters:

  • pid (Integer)

    of process

Returns:



11
12
13
14
15
16
17
# File 'lib/hawatel_ps/windows/proc_table.rb', line 11

def search_by_pid(pid)
  find_by_pid(pid)
  @proc_table.each do |process|
    return process if process.processid.to_s == pid.to_s
  end
  return nil
end