Class: RLPS::Process
- Inherits:
-
Object
- Object
- RLPS::Process
- Defined in:
- lib/rlps/process.rb
Overview
Represents a process
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
-
.get(name: nil, pid: nil) ⇒ Object
:nodoc:.
-
.this_process ⇒ Object
Return this process RLPS::Process object.
Instance Method Summary collapse
-
#initialize(**args) ⇒ Process
constructor
Takes two arguments :name and :pid If called without any arguments it calls RLPS::Process.this_process.
-
#kill!(signal = 'INT') ⇒ Object
Send INT signal to the process as a default behaviour.
-
#still_running? ⇒ Boolean
Returns true if the process is still running.
- #to_i ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(**args) ⇒ Process
Takes two arguments :name and :pid If called without any arguments it calls RLPS::Process.this_process.
Examples
RLPS::Process.new name: “ruby”, pid: 2365
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] || this_process.name @pid = args[:pid] || this_process.pid end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rlps/process.rb', line 6 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/rlps/process.rb', line 6 def pid @pid end |
Class Method Details
.get(name: nil, pid: nil) ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/rlps/process.rb', line 49 def self.get(name: nil, pid: nil) #:nodoc: # TODO end |
Instance Method Details
#kill!(signal = 'INT') ⇒ Object
Send INT signal to the process as a default behaviour. It accepts any signal Kernel#Process takes. More info: Kernel
39 40 41 |
# File 'lib/rlps/process.rb', line 39 def kill!(signal = 'INT') ::Process.kill(signal, @pid) end |
#still_running? ⇒ Boolean
Returns true if the process is still running.
29 30 31 32 33 34 |
# File 'lib/rlps/process.rb', line 29 def still_running? !RLPS.processes.select do |p| p.pid == @pid && p.name.casecmp(@name.downcase).zero? end.empty? end |
#to_i ⇒ Object
24 25 26 |
# File 'lib/rlps/process.rb', line 24 def to_i @pid end |
#to_s ⇒ Object Also known as: inspect
20 21 22 |
# File 'lib/rlps/process.rb', line 20 def to_s "#{@name}: #{@pid}" end |