Class: Procs::ProcessInfo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid, ppid, cmd) ⇒ ProcessInfo

Returns a new instance of ProcessInfo.



8
9
10
11
12
# File 'lib/procs.rb', line 8

def initialize(pid, ppid, cmd)
	@pid  = pid.to_i
	@ppid = ppid.to_i
	@cmd  = cmd.strip
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



7
8
9
# File 'lib/procs.rb', line 7

def cmd
  @cmd
end

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/procs.rb', line 5

def pid
  @pid
end

#ppidObject (readonly)

Returns the value of attribute ppid.



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

def ppid
  @ppid
end

Class Method Details

.info(pid) ⇒ Object



27
28
29
30
# File 'lib/procs.rb', line 27

def ProcessInfo::info(pid)
	p,pp,c=`ps p #{pid} -o pid,ppid,cmd`.scan(/(\d+)\s+(\d+)\s+(.*)$/)[0]
	ProcessInfo.new p.to_i, pp.to_i, c
end

Instance Method Details

#childsObject



32
33
34
# File 'lib/procs.rb', line 32

def childs
	Procs::childs(self.pid)
end

#inspectObject



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

def inspect
	'<Process: pid=%s, ppid=%s, cmd=%s>'%[self.pid, self.ppid, self.cmd]
end

#killObject



14
15
16
17
18
19
20
# File 'lib/procs.rb', line 14

def kill
	Process::kill('KILL', self.pid)
	begin
		Process::wait(self.pid)
	rescue Errno::ECHILD => err
	end
end

#killtreeObject



22
23
24
25
# File 'lib/procs.rb', line 22

def killtree
	self.childs.each{|c| c.killtree}
	self.kill
end

#to_iObject



36
37
38
# File 'lib/procs.rb', line 36

def to_i
	self.pid
end

#to_sObject



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

def to_s
	'<Process: pid=%s, ppid=%s, cmd=%s>'%[self.pid, self.ppid, self.cmd]
end