Skip to content

Instantly share code, notes, and snippets.

@jbbarth
Created January 4, 2017 09:45
Show Gist options
  • Save jbbarth/b00e1fdfde08827e1df3e3057665ff32 to your computer and use it in GitHub Desktop.
Save jbbarth/b00e1fdfde08827e1df3e3057665ff32 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
puts "#{"PID".ljust(7)} PROCESS"
lines = %x(ps auxfwww|grep " simplefl[o]w ").lines.map do |line|
stats, command = line.split("|", 2)
tokens = stats.split
{ pid: tokens[1], command: command }
end
exit if lines == []
while lines.all?{|l| l[:command] && l[:command].match(/^(\|| )/) }
lines = lines.inject([]) do |memo, line|
memo << { pid: line[:pid], command: line[:command].sub(/^./, "") }
memo
end
end
lines.each do |line|
puts "#{line[:pid].ljust(7)} #{line[:command].sub(/^\|/, " ")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment