Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In the GNU utils, ps auxf gives the process list with forest (tree). Is there a equivalent for this command at BSD / OS X systems?

share|improve this question
    
    
Is it desperately important that you use a command line version of it? If you just want to see the tree, why not use "Activity Monitor" and choose "All Processes, Hierarchically"? –  AlanGBaker Oct 28 '11 at 22:45

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
    
Too bad that ps doesn't have this ability, but I'll manage myself with pstree. Thanks for mentioning it! –  vdboor Oct 31 '11 at 14:37

If you really love GNU ps, you can install it onto OSX via one of the big 3 package systems:

pkgsrc (NetBSD) -- my favorite since it works on most popular Unixes

MacPorts (OSX)

Fink (Debian, but does not share the packageset, and of course does not share the builds)

share|improve this answer
    
What's the package called? MacPorts is what I'm looking for, but it'd be helpful for others to know all three. –  Jim Stewart Nov 20 '13 at 22:25

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 erco@seriss.com 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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.