Linux‎ > ‎

pstree - display a tree of processes

Thank you for visiting this page, this page has been update in another link pstree display a tree of proeceses
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.
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

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

$ pstree
     │      └─sshd───bash───su───bash───pstree

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}



Print a PID process tree

$ pstree -a -p 2336
automount,2336 --pid-file /var/run/

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/

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 2569, -p -a
  │   └─{multipathd},1996
  ├─mysqld_safe,2408 /usr/bin/mysqld_safe --datadir=/data/mysql --socket=/data/mysql/mysql.sock --pid-file=/var/run/mysqld/ --basedir=/usr ...
  │   └─mysqld,2567 --basedir=/usr --datadir=/data/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/
  │       ├─{mysqld},2569
  │       ├─{mysqld},2570