Class: HawatelPS::Linux::ProcTable
- Inherits:
-
Object
- Object
- HawatelPS::Linux::ProcTable
- Defined in:
- lib/hawatel_ps/linux/proc_table.rb
Class Method Summary collapse
-
.childs_tree ⇒ Object
private
Find and add childs attribute for process.
-
.proc_table ⇒ Array<ProcInfo>
Return all process instances.
-
.refresh ⇒ Array<ProcInfo>
private
Refresh list of current running processes.
-
.search_by_condition(args) ⇒ Array<ProcInfo>
Return attributes of searched process based on specified condition.
-
.search_by_name(process_name) ⇒ Array<ProcInfo>
Return attributes of searched process based on name or cmdline.
-
.search_by_pid(pid) ⇒ ProcInfo
Return attributes of searched process based on pid.
Class Method Details
.childs_tree ⇒ Object (private)
Find and add childs attribute for process
111 112 113 114 115 116 117 118 119 |
# File 'lib/hawatel_ps/linux/proc_table.rb', line 111 def childs_tree @proc_table.each do |proc_parent| @proc_table.each do |proc_child| if proc_parent.pid == proc_child.ppid proc_parent[:childs].push(proc_child) end end end end |
.proc_table ⇒ Array<ProcInfo>
Return all process instances
89 90 91 92 |
# File 'lib/hawatel_ps/linux/proc_table.rb', line 89 def proc_table refresh return @proc_table end |
.refresh ⇒ Array<ProcInfo> (private)
Refresh list of current running processes
101 102 103 104 105 106 107 |
# File 'lib/hawatel_ps/linux/proc_table.rb', line 101 def refresh @proc_table = Array.new ProcFetch.get_process.each do |proc_attrs| @proc_table.push(ProcInfo.new(proc_attrs)) end childs_tree end |
.search_by_condition(args) ⇒ Array<ProcInfo>
Return attributes of searched process based on specified condition
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hawatel_ps/linux/proc_table.rb', line 57 def search_by_condition(args) refresh attr = args[:attr] oper = args[:oper] value = args[:value] process_list = Array.new @proc_table.each do |process| value = value.to_i if process[:"#{attr}"].is_a? Fixnum value = value.to_f if process[:"#{attr}"].is_a? Float if oper == '>' process_list << process if process[:"#{attr}"] > value if process[:"#{attr}"] elsif oper == '<' process_list << process if process[:"#{attr}"] < value if process[:"#{attr}"] elsif oper == '>=' process_list << process if process[:"#{attr}"] >= value if process[:"#{attr}"] elsif oper == '<=' process_list << process if process[:"#{attr}"] <= value if process[:"#{attr}"] elsif oper == '==' process_list << process if process[:"#{attr}"] == value if process[:"#{attr}"] elsif oper == '!=' process_list << process if process[:"#{attr}"] != value if process[:"#{attr}"] end end return process_list end |
.search_by_name(process_name) ⇒ Array<ProcInfo>
Return attributes of searched process based on name or cmdline
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hawatel_ps/linux/proc_table.rb', line 29 def search_by_name(process_name) refresh process_list = Array.new if process_name =~ /^\/.*\/$/ process_name.slice!(0) process_name = Regexp.new(/#{process_name.chop}/) end @proc_table.each do |process| if process_name.is_a? Regexp process_list << process if process.name =~ process_name || process.cmdline =~ process_name else process_list << process if process.name == "#{process_name}" || process.cmdline == "#{process_name}" end end return process_list end |
.search_by_pid(pid) ⇒ ProcInfo
Return attributes of searched process based on pid
13 14 15 16 17 18 19 |
# File 'lib/hawatel_ps/linux/proc_table.rb', line 13 def search_by_pid(pid) refresh @proc_table.each do |process| return process if process.pid.to_s == pid.to_s end return nil end |