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



56
57
58
# File 'lib/rush/process.rb', line 56

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

Instance Method Details

#==(other) ⇒ Object

:nodoc:



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

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

#alive?Boolean

Returns true if the process is currently running.

Returns:

  • (Boolean)


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

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

#childrenObject

Returns an array of child processes owned by this process.



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

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

#inspectObject

:nodoc:



24
25
26
27
28
29
30
# File 'lib/rush/process.rb', line 24

def inspect   # :nodoc:
	if box.to_s != 'localhost'
		"#{box} #{@pid}: #{@cmdline}"
	else
		"#{@pid}: #{@cmdline}"
	end
end

#kill(options = {}) ⇒ Object

Terminate the process.



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

def kill(options={})
	box.connection.kill_process(pid, options)
end

#parentObject

Returns the Rush::Process parent of this process.



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

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