Class: Bidi2pdf::ProcessTree
- Inherits:
-
Object
- Object
- Bidi2pdf::ProcessTree
- Includes:
- Sys
- Defined in:
- lib/bidi2pdf/process_tree.rb
Instance Method Summary collapse
- #children(of_pid) ⇒ Object
-
#initialize(root_pid = nil) ⇒ ProcessTree
constructor
A new instance of ProcessTree.
- #traverse(&handler) ⇒ Object
Constructor Details
#initialize(root_pid = nil) ⇒ ProcessTree
Returns a new instance of ProcessTree.
8 9 10 11 12 |
# File 'lib/bidi2pdf/process_tree.rb', line 8 def initialize(root_pid = nil) @root_pid = root_pid @process_map = build_process_map connect_children end |
Instance Method Details
#children(of_pid) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/bidi2pdf/process_tree.rb', line 14 def children(of_pid) return [] unless @process_map[of_pid] direct_children = @process_map[of_pid][:children].map do |child_pid| @process_map[child_pid][:info] end (direct_children + direct_children.flat_map { |child| children(child.pid) }).uniq end |
#traverse(&handler) ⇒ Object
24 25 26 27 28 |
# File 'lib/bidi2pdf/process_tree.rb', line 24 def traverse(&handler) handler = method(:print_handler) unless handler.is_a?(Proc) root_pids.each { |pid| traverse_branch(pid, &handler) } end |