What is the OS X / BSD equivalent of the GNU "ps auxf" command? [closed]
pstree is generally part of the default install or easily installable on bsd systems. That's what I use. For example, you can install it via macports on a mac.
Htop is also a really good process viewer, and it has "tree" view as one of it's main options in the lower status bar (F5).
So far I don't believe OSX has a built in that does this.
But here's an answer I posted on stackexchange as well; a small perl script that determines the process hierarchy and prints it in an indented form using the output of OSX's built-in ps(1).
Tested on OSX 10.6 and 10.9, and should work on linux as well (Sci Linux 6).
#!/usr/bin/perl
# treeps -- show ps(1) as process hierarchy -- v1.0 [email protected] 07/08/14
my %p; # Global array of pid info
sub PrintLineage($$) { # Print proc lineage
my ($pid, $indent) = @_;
printf("%s |_ %-8d %s\n", $indent, $pid, $p{$pid}{cmd}); # print
foreach my $kpid (sort {$a<=>$b} @{ $p{$pid}{kids} } ) { # loop thru kids
PrintLineage($kpid, " $indent"); # Recurse into kids
}
}
# MAIN
open(FD, "ps axo ppid,pid,command|");
while ( <FD> ) { # Read lines of output
my ($ppid,$pid,$cmd) = ( $_ =~ m/(\S+)\s+(\S+)\s(.*)/ ); # parse ps(1) lines
$p{$pid}{cmd} = $cmd;
$p{$pid}{kids} = ();
push(@{ $p{$ppid}{kids} }, $pid); # Add our pid to parent's kid
}
PrintLineage(1, ""); # recurse to print lineage starting with pid 1