Class: OsCtl::Lib::ProcessList
- Inherits:
-
Array
- Object
- Array
- OsCtl::Lib::ProcessList
- Defined in:
- lib/libosctl/process_list.rb
Class Method Summary collapse
-
.each(**opts) {|process| ... } ⇒ Object
Iterate over all processes.
Instance Method Summary collapse
-
#initialize {|process| ... } ⇒ ProcessList
constructor
Create an array of system processes.
- #list_processes(**opts) ⇒ Object protected
Constructor Details
#initialize {|process| ... } ⇒ ProcessList
Create an array of system processes
The block can be used to filter out processes for which it returns false.
21 22 23 24 |
# File 'lib/libosctl/process_list.rb', line 21 def initialize(**, &) super() list_processes(**, &) end |
Class Method Details
.each(**opts) {|process| ... } ⇒ Object
Iterate over all processes
6 7 8 9 10 11 12 13 |
# File 'lib/libosctl/process_list.rb', line 6 def self.each(**opts, &block) new(**opts) do |p| block.call(p) next(false) end nil end |
Instance Method Details
#list_processes(**opts) ⇒ Object (protected)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/libosctl/process_list.rb', line 28 def list_processes(**opts) Dir.foreach('/proc') do |entry| next if /^\d+$/ !~ entry || !Dir.exist?(File.join('/proc', entry)) begin p = OsProcess.new(entry.to_i, **opts) next if block_given? && !yield(p) self << p rescue Exceptions::OsProcessNotFound next end end end |