Class: ProcessObserver::LinuxProcess
- Defined in:
- lib/process_observer/process.rb
Overview
Class representing process in Unix.
Instance Attribute Summary collapse
-
#comm ⇒ String
readonly
Command which launched process.
-
#pid ⇒ Integer
readonly
Process ID.
-
#rss ⇒ Integer?
readonly
Amount of used CPU memory in KB.
-
#stat ⇒ String?
readonly
Process status.
-
#time ⇒ String?
readonly
Amount of time process is running.
Attributes inherited from Process
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare with other process by PID.
-
#initialize(options) ⇒ LinuxProcess
constructor
Initialize new process.
-
#inspect(splitter = "; ") ⇒ String
Inspect all stored data.
-
#to_s ⇒ String
PID and command of process.
Constructor Details
#initialize(options) ⇒ LinuxProcess
Initialize new process.
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/process_observer/process.rb', line 191 def initialize() @comm = [:comm].to_s @pid = [:pid].to_i @stat = [:stat] ? [:stat].to_s : nil @time = [:time] ? [:time].to_s : nil @rss = [:rss] ? [:rss].to_i : nil super( name: @comm, pid: @pid, memory: @rss ) end |
Instance Attribute Details
#comm ⇒ String (readonly)
Returns command which launched process.
163 164 165 |
# File 'lib/process_observer/process.rb', line 163 def comm @comm end |
#pid ⇒ Integer (readonly)
Returns process ID.
167 168 169 |
# File 'lib/process_observer/process.rb', line 167 def pid @pid end |
#rss ⇒ Integer? (readonly)
Returns amount of used CPU memory in KB.
179 180 181 |
# File 'lib/process_observer/process.rb', line 179 def rss @rss end |
#stat ⇒ String? (readonly)
Returns process status.
171 172 173 |
# File 'lib/process_observer/process.rb', line 171 def stat @stat end |
#time ⇒ String? (readonly)
Returns amount of time process is running.
175 176 177 |
# File 'lib/process_observer/process.rb', line 175 def time @time end |
Instance Method Details
#==(other) ⇒ Object
Compare with other process by PID.
226 227 228 |
# File 'lib/process_observer/process.rb', line 226 def ==(other) LinuxProcess === other && other.pid == @pid end |
#inspect(splitter = "; ") ⇒ String
Inspect all stored data.
217 218 219 220 221 222 |
# File 'lib/process_observer/process.rb', line 217 def inspect(splitter = "; ") to_s + (@stat ? "#{splitter}Status: #{@stat}" : "") + (@time ? "#{splitter}Time running: #{@time}" : "") + (@rss ? "#{splitter}Memory: #{@rss} KB" : "") end |
#to_s ⇒ String
Returns PID and command of process.
207 208 209 |
# File 'lib/process_observer/process.rb', line 207 def to_s "Process ##{@pid} #{@comm}" end |