pstree - display a tree of processes

pstree  shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.

Without any argument

Without any argument, pstree prints out all the process in hierarchical structure

$ pstree
init─┬─acpid
     ├─atd
     ├─automount───3*[{automount}]
...
     ├─6*[mingetty]
     ├─multipathd───6*[{multipathd}]
     ├─mysqld_safe───mysqld───19*[{mysqld}]
...
     ├─sshd─┬─sshd───bash───mysql
     │      └─sshd───bash───su───bash───pstree
     └─udevd───2*[udevd]

Note:  pstree visually merges identical branches by putting them in square brackets and prefixing them with the repetition count, e.g.

  ├─multipathd
  │   ├─{multipathd}
  │   ├─{multipathd}
  │   ├─{multipathd}
  │   ├─{multipathd}
  │   ├─{multipathd}
  │   └─{multipathd}

Becomes

     ├─multipathd───6*[{multipathd}]

Print a PID process tree

$ pstree -a -p 2336
automount,2336 --pid-file /var/run/autofs.pid
  ├─{automount},2337
  ├─{automount},2338
  └─{automount},2341

Print a user's process tree

$ pstree mysql -a -p
mysqld,2567 --basedir=/usr --datadir=/data/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid--socket=/data/mys
  ├─{mysqld},2569
  ├─{mysqld},2570
  ├─{mysqld},2571
...
  ├─{mysqld},12473
  ├─{mysqld},14847
  └─{mysqld},17285

Highlight the current process and its ancestors

Very much like to print one PID's process tree, but this option not just print the process' subprocesses, it also prints out its ancestors and with highlight. Very useful option.

 

pstree -H 4121,-p -a
...
  ├─gnome-terminal-
  │   ├─bash
  │   │   └─vi a
  │   │       └─bash
  │   │           └─pstree -H 4121,-p -a
  │   ├─gnome-pty-helpe
  │   └─3*[{gnome-terminal-}]
...

Full Syntax

More options to play with

Syntax
Usage: pstree [ -a ] [ -c ] [ -h | -H PID ] [ -l ] [ -n ] [ -p ] [ -u ]
              [ -A | -G | -U ] [ PID | USER ]
       pstree -V
Display a tree of processes.

    -a     show command line arguments
    -A     use ASCII line drawing characters
    -c     don't compact identical subtrees
    -h     highlight current process and its ancestors
    -H PID highlight this process and its ancestors
    -G     use VT100 line drawing characters
    -l     don't truncate long lines
    -n     sort output by PID
    -p     show PIDs; implies -c
    -u     show uid transitions
    -U     use UTF-8 (Unicode) line drawing characters
    -V     display version information
    -Z     show SELinux security contexts
    PID    start at this PID; default is 1 (init)
    USER   show only trees rooted at processes of this user