Thursday, 20th November 2008
pstree is similiar enough to ps, except it displays the processes in a graphical manner, using ascii characters to build up a tree to give a visualisation of how the processes link into one another and what runs what. This can be useful if you need to kill the starter of a process to prevent it from restarting the process you wish to stop. It also visually merges lines of repetition so that if a process is running 8 or 9 times it is only displayed once by pstree but its name is prefixed by the number or occurances of the process and a * to indicated the number of times that the process is currently running.
$ pstree
init-+-6*[WindowMaker]
|-WindowMaker---xterm---bash---mozilla-bin---mozilla-bin---4*[mozilla-bin]
|-7*[Xvnc]
|-apache---12*[apache]
|-apache-ssl-+-15*[apache-ssl]
| `-gcache
|-bdflush
|-bnc
|-cron
|-5*[fetchmail]
|-6*[getty]
|-inetd-+-2*[imapd]
| `-2*[stunnel]
|-java---java---9*[java]
|-keventd
|-khubd
|-7*[kjournald]
|-klogd
|-ksoftirqd_CPU0
|-ksoftirqd_CPU1
|-kswapd
|-kupdated
|-log2mail
|-oidentd
|-postmaster---postmaster---postmaster
|-safe_mysqld---mysqld---mysqld---21*[mysqld]
|-safe_mysqld---mysqld---mysqld---2*[mysqld]
|-2*[screen---bash---ncftp]
|-4*[screen---bash]
|-screen-+-bash
| `-mutt
|-2*[screen---irssi]
|-5*[screen---BitchX]
|-2*[screen---bitchx]
|-screen---2*[bash]
|-2*[screen---ncftp]
|-snmpd
|-snmptrapd
|-snort
|-sshd-+-sshd---sshd---bash---irssi
| |-7*[sshd---sshd---bash]
| |-sshd---sshd---bash-+-2*[talk]
| | `-2*[vim]
| |-sshd---sshd---bash---mutt
| |-sshd---sshd---bash-+-pstree
| | `-talk
| `-sshd---sshd---bash---talk
|-syslog-ng
|-walter
`-xfs
As you can see its a little hard to work out who's running what, but it does give a clear indication of just how the various processes are interconnected. This will probably be the most common way that pstree is used but again man pstree will give a full list of all the options and you can even use pstree to just give the graphical representation of the processes being run by a single user.