Class: Rush::Process

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

Overview

An array of these objects is returned by Rush::Box#processes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, box) ⇒ Process

params is a hash returned by the system-specific method of looking up the process list.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rush/process.rb', line 7

def initialize(params, box)
	@box = box

	@pid = params[:pid].to_i
	@uid = params[:uid].to_i
	@user = params[:user]
	@command = params[:command]
	@cmdline = params[:cmdline]
	@mem = params[:mem]
	@cpu = params[:cpu]
	@parent_pid = params[:parent_pid]
end

Instance Attribute Details

#boxObject (readonly)

Returns the value of attribute box.



3
4
5
# File 'lib/rush/process.rb', line 3

def box
  @box
end

#cmdlineObject (readonly)

Returns the value of attribute cmdline.



3
4
5
# File 'lib/rush/process.rb', line 3

def cmdline
  @cmdline
end

#commandObject (readonly)

Returns the value of attribute command.



3
4
5
# File 'lib/rush/process.rb', line 3

def command
  @command
end

#cpuObject (readonly)

Returns the value of attribute cpu.



3
4
5
# File 'lib/rush/process.rb', line 3

def cpu
  @cpu
end

#memObject (readonly)

Returns the value of attribute mem.



3
4
5
# File 'lib/rush/process.rb', line 3

def mem
  @mem
end

#parent_pidObject (readonly)

Returns the value of attribute parent_pid.



3
4
5
# File 'lib/rush/process.rb', line 3

def parent_pid
  @parent_pid
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/rush/process.rb', line 3

def pid
  @pid
end

#uidObject (readonly)

Returns the value of attribute uid.



3
4
5
# File 'lib/rush/process.rb', line 3

def uid
  @uid
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/rush/process.rb', line 3

def user
  @user
end

Class Method Details

.allObject



52
53
54
# File 'lib/rush/process.rb', line 52

def self.all
	Rush::Box.new('localhost').processes
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



48
49
50
# File 'lib/rush/process.rb', line 48

def ==(other)       # :nodoc:
	pid == other.pid and box == other.box
end

#alive?Boolean

Returns true if the process is currently running.

Returns:

  • (Boolean)


39
40
41
# File 'lib/rush/process.rb', line 39

def alive?
	box.connection.process_alive(pid)
end

#childrenObject

Returns an array of child processes owned by this process.



34
35
36
# File 'lib/rush/process.rb', line 34

def children
	box.processes.select { |p| p.parent_pid == pid }
end

#inspectObject

:nodoc:



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

def inspect   # :nodoc:
	"#{box} process #{@pid}: #{@cmdline}"
end

#killObject

Terminate the process.



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

def kill
	box.connection.kill_process(pid)
end

#parentObject

Returns the Rush::Process parent of this process.



29
30
31
# File 'lib/rush/process.rb', line 29

def parent
	box.processes.select { |p| p.pid == parent_pid }.first
end

#to_sObject

:nodoc:



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

def to_s      # :nodoc:
	inspect
end