Skip to content

Instantly share code, notes, and snippets.

@reneegyllensvaan
Last active December 3, 2018 17:05
Show Gist options
  • Save reneegyllensvaan/96d3d057c8f922896010bfacd64c57ba to your computer and use it in GitHub Desktop.
Save reneegyllensvaan/96d3d057c8f922896010bfacd64c57ba to your computer and use it in GitHub Desktop.
cat <(echo 'my %p; sub PrintLineage($$) { my ($pid, $indent) = @_; printf("%s |_ %-8d %s\n", $indent, $pid, $p{$pid}{cmd}); foreach my $kpid (sort {$a<=>$b} @{ $p{$pid}{kids} } ) { PrintLineage($kpid, " $indent"); } } open(FD, "ps axo ppid,pid,command|"); while ( <FD> ) { my ($ppid,$pid,$cmd) = ( $_ =~ m/(\S+)\s+(\S+)\s(.*)/ ); $p{$pid}{cmd} = $cmd; push(@{ $p{$ppid}{kids} }, $pid); } PrintLineage(($ARGV[0]) ? $ARGV[0] : 1, "");' |perl) <(ps aux)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment