pstree command displays a hierarchical list of processes in a tree format. pstree is very handy for understanding how parent/child process relationships are set up.
If the PID is specified, the displayed tree is rooted at that process. Otherwise, it is rooted at the init process, which has PID 1. If a user (a valid username) is specified, trees for all processes owned by user are shown. The tree is represented using characters that appear as lines, such as | for vertical lines and + for intersections (VT100 line-drawing characters, displayed as solid lines by most terminals, are optional).
The command can be run without providing any options.
To display tree of processes with their PIDs, use the -p switch.
# pstree -p init(1)-+-atd(468) |-bdflush(5) |-crond(454) |-httpd(440)-+-httpd(450) | |-httpd(451) | |-httpd(452) | |-httpd(453) | |-httpd(455) | |-httpd(456) | |-httpd(457) | '-httpd(458) |-keventd(2) |-kjournald(7) |-klogd(335) |-ksoftirqd_CPU0(3) |-kswapd(4) |-kupdated(6) |-login(475)---bash(478)---pstree(518) |-sendmail(420) |-sshd(385) |-syslogd(330) '-xinetd(402)
If you encounter the below error while running the pstree command:
pstree: command not found
you may try installing the package as shown below as per your choice of distribution.
|OS X||brew install pstree|
|Debian||apt-get install psmisc|
|Ubuntu||apt-get install psmisc|
|Alpine||apk add psmisc|
|Arch Linux||pacman -S psmisc|
|Kali Linux||apt-get install psmisc|
|CentOS||yum install psmisc|
|Fedora||dnf install psmisc|
|Raspbian||apt-get install psmisc|
pstree Command Examples
1. Display a tree of processes:
2. Display a tree of processes with PIDs:
# pstree -p
3. Display all process trees rooted at processes owned by specified user:
# pstree user