Class: Procs::ProcessInfo
- Inherits:
-
Object
- Object
- Procs::ProcessInfo
- Defined in:
- lib/procs.rb
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#ppid ⇒ Object
readonly
Returns the value of attribute ppid.
Class Method Summary collapse
Instance Method Summary collapse
- #childs ⇒ Object
-
#initialize(pid, ppid, cmd) ⇒ ProcessInfo
constructor
A new instance of ProcessInfo.
- #inspect ⇒ Object
- #kill ⇒ Object
- #killtree ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
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
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
7 8 9 |
# File 'lib/procs.rb', line 7 def cmd @cmd end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/procs.rb', line 5 def pid @pid end |
#ppid ⇒ Object (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
#inspect ⇒ Object
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 |
#kill ⇒ Object
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 |
#killtree ⇒ Object
22 23 24 25 |
# File 'lib/procs.rb', line 22 def killtree self.childs.each{|c| c.killtree} self.kill end |
#to_i ⇒ Object
36 37 38 |
# File 'lib/procs.rb', line 36 def to_i self.pid end |
#to_s ⇒ Object
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 |