Class Rush::ProcessSet
In: lib/rush/process_set.rb
Parent: Object

A container for processes that behaves like an array, and adds process-specific operations on the entire set, like kill.

Example:

  processes.filter(:cmdline => /mongrel_rails/).kill

Methods

==   alive?   each   filter   kill   method_missing   new  

Included Modules

Enumerable

Attributes

processes  [R] 

Public Class methods

[Source]

    # File lib/rush/process_set.rb, line 11
11:         def initialize(processes)
12:                 @processes = processes
13:         end

Public Instance methods

[Source]

    # File lib/rush/process_set.rb, line 50
50:         def ==(other)
51:                 if other.class == self.class
52:                         other.processes == processes
53:                 else
54:                         to_a == other
55:                 end
56:         end

Check status of all processes in the set, returns an array of booleans.

[Source]

    # File lib/rush/process_set.rb, line 40
40:         def alive?
41:                 processes.map { |p| p.alive? }
42:         end

[Source]

    # File lib/rush/process_set.rb, line 46
46:         def each
47:                 processes.each { |p| yield p }
48:         end

Filter by any field that the process responds to. Specify an exact value, or a regular expression. All conditions are put together as a boolean AND, so these two statements are equivalent:

  processes.filter(:uid => 501).filter(:cmdline => /ruby/)
  processes.filter(:uid => 501, :cmdline => /ruby/)

[Source]

    # File lib/rush/process_set.rb, line 22
22:         def filter(conditions)
23:                 Rush::ProcessSet.new(
24:                         processes.select do |p|
25:                                 conditions.all? do |key, value|
26:                                         value.class == Regexp ?
27:                                                 value.match(p.send(key)) :
28:                                                 p.send(key) == value
29:                                 end
30:                         end
31:                 )
32:         end

Kill all processes in the set.

[Source]

    # File lib/rush/process_set.rb, line 35
35:         def kill
36:                 processes.each { |p| p.kill }
37:         end

All other messages (like size or first) are passed through to the array.

[Source]

    # File lib/rush/process_set.rb, line 59
59:         def method_missing(meth, *args)
60:                 processes.send(meth, *args)
61:         end

[Validate]