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

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

$ pstree
init─┬─acpid
     ├─atd
     ├─automount───3*[{automount}]
     ├─crond
     ├─dbus-daemon
     ├─gmond
     ├─irqbalance
     ├─6*[mingetty]
     ├─multipathd───6*[{multipathd}]
     ├─mysqld_safe───mysqld───19*[{mysqld}]
     ├─ntpd
     ├─rpc.statd
     ├─rpcbind
     ├─rsyslogd───3*[{rsyslogd}]
     ├─2*[sendmail]
     ├─smallhsm_libd.p───4*[smallhsm_libd.p]
     ├─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 2569, -p -a
init,1
  ├─acpid,2302
...
  │   └─{multipathd},1996
  ├─mysqld_safe,2408 /usr/bin/mysqld_safe --datadir=/data/mysql --socket=/data/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr ...
  │   └─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
...




Comments