Class: RLPS::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/rlps/process.rb

Overview

Represents a process

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Process

Takes two arguments :name and :pid If called without any arguments it calls RLPS::Process.this_process.



11
12
13
14
15
16
17
18
# File 'lib/rlps/process.rb', line 11

def initialize(**args)
  #-- other = args.select { |k, _v| ((k == :name) &&
  # !args[k].nil?) || ((k == :pid) && !args[k].nil?) }
  # raise if (other.count == 0) || (args.count != 2)
  # TODO check if this process actually exists
  @name = args[:name] || RLPS.this_process.name
  @pid = args[:pid]   || RLPS.this_process.pid
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rlps/process.rb', line 6

def name
  @name
end

#pidObject (readonly)

Returns the value of attribute pid.



6
7
8
# File 'lib/rlps/process.rb', line 6

def pid
  @pid
end

Instance Method Details

#==(obj) ⇒ Object



24
25
26
# File 'lib/rlps/process.rb', line 24

def ==(obj)
  obj.name.casecmp(@name).zero?
end

#is_running?Boolean

Returns true if the process is running.

Returns:

  • (Boolean)


33
34
35
# File 'lib/rlps/process.rb', line 33

def is_running?
  !RLPS.processes.select { |p| p == self }.empty?
end

#kill!(signal = 'INT') ⇒ Object

Send INT signal to the process as a default behaviour. It accepts any signal Kernel#Process takes. More info: Kernel



40
41
42
# File 'lib/rlps/process.rb', line 40

def kill!(signal = 'INT')
  ::Process.kill(signal, @pid)
end

#to_iObject



28
29
30
# File 'lib/rlps/process.rb', line 28

def to_i
  @pid
end

#to_sObject Also known as: inspect



20
21
22
# File 'lib/rlps/process.rb', line 20

def to_s
  "#{@name}: #{@pid}"
end