Class: RLPS::Process

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

Overview

Represents a process

Instance Attribute Summary collapse

Class Method 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.

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

#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

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

.this_processObject

Return this process RLPS::Process object.



44
45
46
47
# File 'lib/rlps/process.rb', line 44

def self.this_process
  process = RLPS.processes.select { |p| p.pid == ::Process.pid }
  RLPS::Process.new name: process[0].name, pid: ::Process.pid
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.

Returns:

  • (Boolean)


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_iObject



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

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