class ProcessObserver::WindowsProcess

Class representing process in Windows.

Attributes

cpu_time[R]

@return [String, nil] process runtime.

image_name[R]

@return [String] name of the executable.

mem_usage[R]

@return [Integer, nil] memory usage in KB.

modules[R]

@return [Array<String>] used DLLs.

package_name[R]

@return [String, nil] name of app package name.

pid[R]

@return [Integer] process ID.

services[R]

@return [Array<String>] services.

session[R]

@return [Integer, nil] session number.

session_name[R]

@return [String, nil] session name.

status[R]

@return [String, nil] process status.

user_name[R]

@return [String, nil] user which started process.

window_title[R]

@return [String, nil] title of process window.

Public Class Methods

new(options) click to toggle source

Initialize new process.

@param options [Hash]

@option options [String] image_name name of the executable. @option options [Integer] pid process ID. @option options [String, nil] session_name session name. @option options [Integer, nil] session session number. @option options [Integer, nil] mem_usage memory usage in KB. @option options [String, nil] status process status. @option options [String, nil] user_name user which started process. @option options [String, nil] cpu_time process runtime. @option options [String, nil] window_title title of process window. @option options [Array<String>, nil] services services. @option options [Array<String>, nil] modules used DLLs. @option options [String, nil] package_name name of app package name.

Calls superclass method ProcessObserver::Process::new
# File lib/process_observer/process.rb, line 104
def initialize(options)
  @image_name   = options[:image_name].to_s
  @pid          = options[:pid].to_i
  @session_name = options[:session_name] ? options[:session_name].to_s                     : nil
  @session      = options[:session]      ? options[:session].to_i                          : nil
  @mem_usage    = options[:mem_usage]    ? options[:mem_usage].to_s.gsub(/[^\d]/, "").to_i : nil
  @status       = options[:status]       ? options[:status].to_s                           : nil
  @user_name    = options[:user_name]    ? options[:user_name].to_s                        : nil
  @cpu_time     = options[:cpu_time]     ? options[:cpu_time].to_s                         : nil
  @window_title = options[:window_title] ? options[:window_title].to_s                     : nil
  @services     = options[:services]     ? options[:services].to_s.split(",")              : []
  @modules      = options[:modules]      ? options[:modules].to_s.split(",")               : []
  @package_name = options[:package_name] ? options[:package_name].to_s                     : nil

  super(
    name: @image_name,
    pid: @pid,
    memory: @mem_usage
  )
end

Public Instance Methods

==(other) click to toggle source

Compare with other process by PID.

# File lib/process_observer/process.rb, line 151
def ==(other)
  WindowsProcess === 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 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() click to toggle source

@return [String] PID and name of process.

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