14

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?

  • 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
9

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.

| 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
  • 7
    or brew install pstree with hombrew – cwd Mar 29 '15 at 13:28
  • @cwd your comment should be an answer :) – okutane May 26 '17 at 11:16
6

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).

enter image description here

| improve this answer | |
  • 2
    To install in OSX with homebrew, use brew install htop. – jsears Nov 18 '16 at 15:46
3

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
| improve this answer | |
1

This doesn't work on OSX, but for FreeBSD it's the ps(1) command with -d option. Looks like this:

% ps auxwwwd
USER    PID  %CPU %MEM   VSZ   RSS TT  STAT STARTED      TIME COMMAND
root      0   0,0  0,0     0   304  -  DLs  15:23     0:05,12 [kernel]
root     11 400,0  0,0     0    64  -  RL   15:23   712:54,09 - [idle]
root      1   0,0  0,0 10004   140  -  ILs  15:23     0:00,02 - /sbin/init --
root    309   0,0  0,0 11392  1372  -  Is   15:23     0:00,08 |-- dhclient: em0 [priv] (dhclient)
_dhcp   355   0,0  0,0 11556  1444  -  Is   15:23     0:00,06 |-- dhclient: em0 (dhclient)
root    404   0,0  0,0 14236   664  -  Ss   15:23     0:01,57 |-- /sbin/devd
root    546   0,0  0,0 11360  1320  -  Ss   15:23     0:00,63 |-- /usr/sbin/syslogd -s
root    678   0,0  0,0 17908  1252  -  Is   15:24     0:00,00 |-- /usr/sbin/sshd
root    751   0,0  0,0 18312  1312  -  Is   15:25     0:00,04 | `-- sshd: trasz [priv] (sshd)
trasz   753   0,0  0,0 18948  2012  -  S    15:25     0:01,83 |   `-- sshd: trasz@pts/0 (sshd)
trasz   754   0,0  0,0 13948     0  0  IWs  -         0:00,00 |     `-- -zsh (zsh)
trasz   765   0,0  0,0 15164  1456  0  I+   15:25     0:00,01 |       `-- tmux: client (/tmp/tmux-1001/default) (tmux)
root    681   0,0  0,0 15744  1740  -  Ss   15:24     0:00,39 |-- sendmail: accepting connections (sendmail)
smmsp   684   0,0  0,0 15588   804  -  Is   15:24     0:00,01 |-- sendmail: Queue runner@00:30:00 for /var/spool/clientmqueue (sendmail)
root    688   0,0  0,0 11384   640  -  Is   15:24     0:00,10 |-- /usr/sbin/cron -s
root    733   0,0  0,0 12428   484  -  Is   15:24     0:00,04 |-- /usr/sbin/autounmountd
root    738   0,0  0,0 10860  1112  -  Is   15:24     0:00,00 |-- /usr/sbin/automountd
trasz   767   0,0  0,4 30036 17168  -  Ss   15:25     0:01,97 |-- tmux: server (/tmp/tmux-1001/default) (tmux)
trasz   768   0,0  0,1 13888  2592  1  Is+  15:25     0:00,05 | |-- -zsh (zsh)
trasz 11313   0,0  0,1 13952  3984  2  Is+  21:05     0:00,07 | |-- -zsh (zsh)
trasz 11531   0,0  0,1 13952  3980  3  Is+  21:55     0:00,05 | |-- -zsh (zsh)
trasz 37987   0,0  0,1 13920  4260  5  Ss   22:06     0:00,04 | |-- -zsh (zsh)
trasz 37998   0,0  0,1 11796  2512  5  R+   22:07     0:00,00 | | `-- ps auxwwwd
trasz 25549   0,0  0,1 13952  3980  4  Is+  21:57     0:00,08 | `-- -zsh (zsh)
root    743   0,0  0,0 10900  1100 v0  Is+  15:24     0:00,00 |-- /usr/libexec/getty Pc ttyv0
root    744   0,0  0,0 10900  1100 v1  Is+  15:24     0:00,01 |-- /usr/libexec/getty Pc ttyv1
root    745   0,0  0,0 10900  1100 v2  Is+  15:24     0:00,00 |-- /usr/libexec/getty Pc ttyv2
root    746   0,0  0,0 10900  1100 v3  Is+  15:24     0:00,01 |-- /usr/libexec/getty Pc ttyv3
root    747   0,0  0,0 10900  1100 v4  Is+  15:24     0:00,00 |-- /usr/libexec/getty Pc ttyv4
root    748   0,0  0,0 10900  1100 v5  Is+  15:24     0:00,00 |-- /usr/libexec/getty Pc ttyv5
root    749   0,0  0,0 10900  1100 v6  Is+  15:24     0:00,00 |-- /usr/libexec/getty Pc ttyv6
root    750   0,0  0,0 10900  1100 v7  Is+  15:24     0:00,01 `-- /usr/libexec/getty Pc ttyv7
root      2   0,0  0,0     0    16  -  DL   15:23     0:00,00 - [crypto]
root      3   0,0  0,0     0    16  -  DL   15:23     0:00,00 - [crypto returns]
root      4   0,0  0,0     0    32  -  DL   15:23     2:16,26 - [cam]
root      5   0,0  0,0     0    16  -  DL   15:23     0:00,00 - [mpt_recovery0]
root      6   0,0  0,0     0    16  -  DL   15:23     0:00,01 - [soaiod1]
root      7   0,0  0,0     0    16  -  DL   15:23     0:00,01 - [soaiod2]
root      8   0,0  0,0     0    16  -  DL   15:23     0:00,01 - [soaiod3]
root      9   0,0  0,0     0    16  -  DL   15:23     0:00,01 - [soaiod4]
root     10   0,0  0,0     0    16  -  DL   15:23     0:00,00 - [audit]
root     12   0,0  0,0     0   800  -  WL   15:23     2:21,06 - [intr]
root     13   0,0  0,0     0    48  -  DL   15:23     0:00,03 - [geom]
root     14   0,0  0,0     0   240  -  DL   15:23     0:10,36 - [usb]
root     15   0,0  0,0     0    16  -  DL   15:23     0:00,00 - [sctp_iterator]
root     16   0,0  0,0     0    16  -  DL   15:23     0:23,43 - [rand_harvestq]
root     17   0,0  0,0     0    48  -  DL   15:23     0:35,10 - [pagedaemon]
root     18   0,0  0,0     0    16  -  DL   15:23     0:05,36 - [vmdaemon]
root     19   0,0  0,0     0    32  -  DL   15:23     1:10,04 - [bufdaemon]
root     20   0,0  0,0     0    16  -  DL   15:23     0:06,68 - [bufspacedaemon]
root     21   0,0  0,0     0    16  -  DL   15:23     0:35,66 - [syncer]
root     22   0,0  0,0     0    16  -  DL   15:23     0:00,86 - [vnlru]
root     23   0,0  0,0     0    16  -  DL   15:23     0:04,96 - [racctd]
| improve this answer | |
0

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)

| improve this answer | |
  • 4
    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
  • 2
    -1 - seems somewhat incorrect. if it is right, please support your answer with more details on how to install using these package systems rather than just mentioning the package management systems (esp. MacPorts ) – cwd Mar 29 '15 at 13:41
0

Here is a link to the answer I posted on stackexchange: https://apple.stackexchange.com/a/383505/364338

Link to my version (wrapper) of "ps": https://github.com/jhthorsen/snippets/blob/master/bin/ps

--- Update ---

I made a different script that takes (should take?) all the arguments you can normally give to "ps" on OSX:

https://github.com/jhthorsen/snippets/blob/master/bin/ps

Example output:

$ ps Af
   PID TTY      STAT      TIME COMMAND
     1 ??       Ss   198:44.08 /sbin/launchd
   141 ??       Ss     2:40.76   \_ /usr/sbin/syslogd
   142 ??       Ss     6:54.11   \_ /usr/libexec/UserEventAgent (System)
   145 ??       Ss     0:32.48   \_ /System/Library/PrivateFrameworks/Uninstall.framework/Resources/uninstalld
   146 ??       Ss     1:12.84   \_ /usr/libexec/kextd
   147 ??       Ss    18:51.47   \_ /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.f
   148 ??       Ss     0:14.31   \_ /System/Library/PrivateFrameworks/MediaRemote.framework/Support/mediaremoted
   151 ??       Ss    59:43.39   \_ /usr/sbin/systemstats --daemon
   441 ??       S      0:05.39       \_ /usr/sbin/systemstats --logger-helper /private/var/db/systemstats
...

> ps Af -o ppid,pid,cpu,command
  PPID   PID CPU COMMAND
     0     1   0 /sbin/launchd
     1   141   0   \_ /usr/sbin/syslogd
     1   142   0   \_ /usr/libexec/UserEventAgent (System)
     1   145   0   \_ /System/Library/PrivateFrameworks/Uninstall.framework/Resources/uninstalld
     1   146   0   \_ /usr/libexec/kextd
     1   147   0   \_ /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versi
     1   148   0   \_ /System/Library/PrivateFrameworks/MediaRemote.framework/Support/mediaremoted
     1   151   0   \_ /usr/sbin/systemstats --daemon
   151   441   0       \_ /usr/sbin/systemstats --logger-helper /private/var/db/systemstats
| improve this answer | |
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – bjoster Mar 3 at 13:18
  • 1
    Sorry about that. #newbieposting – Jan Henning Thorsen Mar 4 at 4:47

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