Class: ProcessObserver::WindowsProcess
- Defined in:
- lib/process_observer/process.rb
Overview
Class representing process in Windows.
Instance Attribute Summary collapse
-
#cpu_time ⇒ String?
readonly
Process runtime.
-
#image_name ⇒ String
readonly
Name of the executable.
-
#mem_usage ⇒ Integer?
readonly
Memory usage in KB.
-
#modules ⇒ Array<String>
readonly
Used DLLs.
-
#package_name ⇒ String?
readonly
Name of app package name.
-
#pid ⇒ Integer
readonly
Process ID.
-
#services ⇒ Array<String>
readonly
Services.
-
#session ⇒ Integer?
readonly
Session number.
-
#session_name ⇒ String?
readonly
Session name.
-
#status ⇒ String?
readonly
Process status.
-
#user_name ⇒ String?
readonly
User which started process.
-
#window_title ⇒ String?
readonly
Title of process window.
Attributes inherited from Process
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare with other process by PID.
-
#initialize(options) ⇒ WindowsProcess
constructor
Initialize new process.
-
#inspect(splitter = "; ") ⇒ String
Inspect all stored data.
-
#to_s ⇒ String
PID and name of process.
Constructor Details
#initialize(options) ⇒ WindowsProcess
Initialize new process.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/process_observer/process.rb', line 104 def initialize() @image_name = [:image_name].to_s @pid = [:pid].to_i @session_name = [:session_name] ? [:session_name].to_s : nil @session = [:session] ? [:session].to_i : nil @mem_usage = [:mem_usage] ? [:mem_usage].to_s.gsub(/[^\d]/, "").to_i : nil @status = [:status] ? [:status].to_s : nil @user_name = [:user_name] ? [:user_name].to_s : nil @cpu_time = [:cpu_time] ? [:cpu_time].to_s : nil @window_title = [:window_title] ? [:window_title].to_s : nil @services = [:services] ? [:services].to_s.split(",") : [] @modules = [:modules] ? [:modules].to_s.split(",") : [] @package_name = [:package_name] ? [:package_name].to_s : nil super( name: @image_name, pid: @pid, memory: @mem_usage ) end |
Instance Attribute Details
#cpu_time ⇒ String? (readonly)
Returns process runtime.
69 70 71 |
# File 'lib/process_observer/process.rb', line 69 def cpu_time @cpu_time end |
#image_name ⇒ String (readonly)
Returns name of the executable.
41 42 43 |
# File 'lib/process_observer/process.rb', line 41 def image_name @image_name end |
#mem_usage ⇒ Integer? (readonly)
Returns memory usage in KB.
57 58 59 |
# File 'lib/process_observer/process.rb', line 57 def mem_usage @mem_usage end |
#modules ⇒ Array<String> (readonly)
Returns used DLLs.
81 82 83 |
# File 'lib/process_observer/process.rb', line 81 def modules @modules end |
#package_name ⇒ String? (readonly)
Returns name of app package name.
85 86 87 |
# File 'lib/process_observer/process.rb', line 85 def package_name @package_name end |
#pid ⇒ Integer (readonly)
Returns process ID.
45 46 47 |
# File 'lib/process_observer/process.rb', line 45 def pid @pid end |
#services ⇒ Array<String> (readonly)
Returns services.
77 78 79 |
# File 'lib/process_observer/process.rb', line 77 def services @services end |
#session ⇒ Integer? (readonly)
Returns session number.
53 54 55 |
# File 'lib/process_observer/process.rb', line 53 def session @session end |
#session_name ⇒ String? (readonly)
Returns session name.
49 50 51 |
# File 'lib/process_observer/process.rb', line 49 def session_name @session_name end |
#status ⇒ String? (readonly)
Returns process status.
61 62 63 |
# File 'lib/process_observer/process.rb', line 61 def status @status end |
#user_name ⇒ String? (readonly)
Returns user which started process.
65 66 67 |
# File 'lib/process_observer/process.rb', line 65 def user_name @user_name end |
#window_title ⇒ String? (readonly)
Returns title of process window.
73 74 75 |
# File 'lib/process_observer/process.rb', line 73 def window_title @window_title end |
Instance Method Details
#==(other) ⇒ Object
Compare with other process by PID.
151 152 153 |
# File 'lib/process_observer/process.rb', line 151 def ==(other) WindowsProcess === other && other.pid == @pid end |
#inspect(splitter = "; ") ⇒ String
Inspect all stored data.
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/process_observer/process.rb', line 137 def inspect(splitter = "; ") to_s + (@session_name || @session ? "#{splitter}Session: #{@session_name}(#{@session})" : "") + (@mem_usage ? "#{splitter}Memory usage: #{@mem_usage} KB" : "") + (@status ? "#{splitter}Status: #{@status}" : "") + (@user_name || @cpu_time ? "#{splitter}Launched by: #{@user_name}, runs for #{@cpu_time}" : "") + (@window_title ? "#{splitter}Title: #{@window_title}" : "") + (@services.empty? ? "" : "#{splitter}Services: #{@services.join(",")}") + (@modules.empty? ? "" : "#{splitter}Modules: #{@modules.join(",")}") + (@package_name ? "#{splitter}Package name: #{@package_name}" : "") end |
#to_s ⇒ String
Returns PID and name of process.
127 128 129 |
# File 'lib/process_observer/process.rb', line 127 def to_s "Process ##{@pid} #{@image_name}" end |