class ProcessObserver::LinuxProcess

Class representing process in Unix.

Attributes

comm[R]

@return [String] command which launched process.

pid[R]

@return [Integer] process ID.

rss[R]

@return [Integer, nil] amount of used CPU memory in KB.

stat[R]

@return [String, nil] process status.

time[R]

@return [String, nil] amount of time process is running.

Public Class Methods

new(options) click to toggle source

Initialize new process.

@param options [Hash]

@option options [String] comm command which launched process. @option options [Integer] pid process ID. @option options [String, nil] stat process status. @option options [String, nil] time amount of time process is running. @option options [Integer, nil] rss amount of used CPU memory in KB.

Calls superclass method ProcessObserver::Process::new
# File lib/process_observer/process.rb, line 191
def initialize(options)
  @comm = options[:comm].to_s
  @pid  = options[:pid].to_i
  @stat = options[:stat] ? options[:stat].to_s : nil
  @time = options[:time] ? options[:time].to_s : nil
  @rss  = options[:rss]  ? options[:rss].to_i  : nil

  super(
    name: @comm,
    pid: @pid,
    memory: @rss
  )
end

Public Instance Methods

==(other) click to toggle source

Compare with other process by PID.

# File lib/process_observer/process.rb, line 226
def ==(other)
  LinuxProcess === other && other.pid == @pid
end
inspect(splitter = "; ") click to toggle source

Inspect all stored data.

@param [String] splitter

@return [String] all accessable info in human-readable form.

# 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() click to toggle source

@return [String] PID and command of process.

# File lib/process_observer/process.rb, line 207
def to_s
  "Process ##{@pid} #{@comm}"
end