Skip to content

Instantly share code, notes, and snippets.

@yazgoo
Created May 22, 2014 09:29
Show Gist options
  • Save yazgoo/b5aaec9350a1aaacd152 to your computer and use it in GitHub Desktop.
Save yazgoo/b5aaec9350a1aaacd152 to your computer and use it in GitHub Desktop.
arrange process snapshot in a tree
#!/usr/bin/ruby
groups = {}
STDIN.each_line do |line|
items = line.split
pid = items[ARGV[0].to_i]
ppid = items[ARGV[1].to_i]
groups[ppid] = [] if groups[ppid].nil?
groups[ppid] << [pid, line]
end
def print_tree groups, cmd, ppid, tab = ""
print "#{tab}+ #{ppid} #{cmd.split.last}\n"
groups[ppid].each do |pid, line|
print_tree groups, line, pid, (tab + " ")
end if not groups[ppid].nil?
end
print_tree groups, 'init', '1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment