Class: OsCtl::Lib::ProcessList

Inherits:
Array
  • Object
show all
Defined in:
lib/libosctl/process_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ProcessList

Returns a new instance of ProcessList



3
4
5
# File 'lib/libosctl/process_list.rb', line 3

def initialize(&block)
  list_processes(&block)
end

Instance Method Details

#list_processesObject (protected)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/libosctl/process_list.rb', line 8

def list_processes
  Dir.foreach('/proc') do |entry|
    next if /^\d+$/ !~ entry || !Dir.exist?(File.join('/proc', entry))

    p = OsProcess.new(entry.to_i)

    begin
      next if block_given? && !yield(p)
    rescue Exceptions::OsProcessNotFound
      next
    end

    self << p
  end
end