Skip to content

Instantly share code, notes, and snippets.

@jbbarth
Created September 12, 2016 15:56
Show Gist options
  • Save jbbarth/615292963e13249d7abf838578376d64 to your computer and use it in GitHub Desktop.
Save jbbarth/615292963e13249d7abf838578376d64 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def children(ps, pid)
ps.select do |p|
p.split[2] == pid
end
end
def pid_from_line(line)
line.split[1]
end
def display_proc(line)
line.split[7..-1].join " "
end
ps = %x(ps -edf).lines.map(&:strip)
ps.grep(/pytho[n].*supervisord -c/).each do |main_proc|
puts display_proc(main_proc)
children(ps, pid_from_line(main_proc)).each do |child|
puts " \\_ [#{children(ps, pid_from_line(child)).count.to_s.rjust(2)}] #{display_proc(child)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment