Module: Mxup::ProcessProbe
- Defined in:
- lib/mxup/process_probe.rb
Overview
Walks the process tree from a pane PID down to the interesting leaf, and reads ‘ps` fields from an arbitrary pid. Used by StatusView to show the actual command the user cares about (not the `zsh -c` wrapping it).
Class Method Summary collapse
-
.leaf_pid(pid) ⇒ Object
Follow pgrep -P down the descendant tree until a leaf (no children) is reached.
- .ps_field(pid, field) ⇒ Object
Class Method Details
.leaf_pid(pid) ⇒ Object
Follow pgrep -P down the descendant tree until a leaf (no children) is reached. Falls back to the starting pid if pgrep is unavailable.
12 13 14 15 16 17 18 19 20 |
# File 'lib/mxup/process_probe.rb', line 12 def leaf_pid(pid) current = pid loop do child = `pgrep -P #{current} 2>/dev/null`.strip.split("\n").first break if child.nil? || child.empty? current = child.to_i end current end |
.ps_field(pid, field) ⇒ Object
22 23 24 25 |
# File 'lib/mxup/process_probe.rb', line 22 def ps_field(pid, field) val = `ps -p #{pid} -o #{field}= 2>/dev/null`.strip val.empty? ? nil : val end |