Linux/Unix: pstree Command Examples: See A Tree Of Processes

pstree command

I am a new Linux user. How do I display the process on the Linux based server or desktop/laptop in easy to read tree format using bash shell prompt?

Linux and Unix are multitasking operating systems i.e. a system that can run multiple tasks (process) during the same period of time. A process is nothing but a running program (command) on Linux or Unix-like systems.[donotprint]

pstree command details
DescriptionSee running processes in the
form of a tree diagram
Root privilegesNo
Estimated completion time10m
[/donotprint] The pstree command shows running processes as a tree.



Display running processes as a tree on Linux


The basic syntax is as follows:



pstree pid


pstree user


pstree [options] pid|user

NOTE: If pid given as a command line argument, start at this PID; default is 1 (init). if user given as a command line argument, show only trees rooted at processes of this user. pstree only accept one argument, and that argument can be either the user or a pid.

Install pstree on Unix

By default the pstree command installed and available on Linux operating systems only. For Unix-like system such as FreeBSD, OS X and others you need to install it using either source code or third party binary repos. You can compile pstree under most unixes, tested are AIX, Linux, HP-UX, A/UX, SunOS, Solaris, (Free|Open|Net)BSD, MacOSX/Darwin, and others. Use wget command to grab the source code:
$ wget
Use tar command to extract files and build the source code with c compiler (cc):
$ tar zxvf pstree.tar.gz
$ cc -O -o pstree pstree.c
## install binary in /usr/local/bin/ directory ##
$ sudo cp pstree /usr/local/bin

Sample outputs:

Animated gif 01: Installing pstree on Unix operating systems

Animated gif 01: Installing pstree on Unix operating systems

Install pstree on MacOS X

Type the following command:
$ brew install pstree

pstree command examples

To see a tree diagram of all the processes currently on the server, type:
# pstree
# pstree | less
# pstree | more

Sample outputs:

Fig.01: pstree command in action

Fig.01: pstree command in action

At the top of the diagram, you will the process init which is the first process that is started when Linux comes on line. init is the parent of all processes on the system, it is executed by the kernel and is responsible for starting all other processes. You can use ASCII characters to draw the tree by passing the -A option:
# pstree -A

Display command line arguments

To see the list of command line arguments, pass the -a option:
$ pstree -a
Sample outputs:

Fig.02: Display running processes along with command  line  arguments

Fig.02: Display running processes along with command line arguments

Display PIDs

To show PIDS for each process name, pass the -p option:
$ pstree -p
Sample outputs:

           |                       `-{gmain}(2984)
           |                 |-{libvirtd}(20178)
           |                 |-{libvirtd}(20179)
           |                 |-{libvirtd}(20180)
           |                 |-{libvirtd}(20181)
           |                 |-{libvirtd}(20182)
           |                 |-{libvirtd}(20183)
           |                 |-{libvirtd}(20184)
           |                 |-{libvirtd}(20185)
           |                 |-{libvirtd}(20186)
           |                 |-{libvirtd}(20187)
           |                 |-{libvirtd}(20188)
           |                 |-{libvirtd}(20189)
           |                 |-{libvirtd}(20190)
           |                 `-{libvirtd}(20191)

           |                                    |-{corefreqd/0}(11909)
           |                                    |-{corefreqd/1}(11910)
           |                                    |-{corefreqd/2}(11911)
           |                                    |-{corefreqd/3}(11912)
           |                                    |-{corefreqd/4}(11913)
           |                                    |-{corefreqd/5}(11914)
           |                                    |-{corefreqd/6}(11915)
           |                                    `-{corefreqd/7}(11916)

How do I sort processes?

To sort processes with the same ancestor by PID instead of by name i.e. numeric sort, pass the -n options as follows:
$ pstree -n
$ pstree -np

How can I see who is the owner/user of a process?

To find out the owner of a process in parenthesis, pass the -u option to pstree command:
$ pstree -u
Sample outputs:

        |                 `-{gmain}
        |                       |                 `-{gmain}
        |                       |-agetty
        |                       |-atd(100001)
        |                       |-cron
        |                       |-dbus-daemon(100107)
        |                       |-dhclient
        |                       |-lighttpd(100033)
        |                       |-memcached(100113)---5*[{memcached}]

How can I highlight the current process and its ancestors?

Pass the -h option to highlight the current process and its ancestors. Pass -H option highlight the specified process (by name/pid):
$ pstree -h
OR highlight process with PID # 60093:
$ pstree -H 60093
Sample outputs:

Fig. 03: Highlighting processes

Fig. 03: Highlighting processes

How can I view a process by PID or user?

The pstree can either accept PID or username as a command line argument. The syntax is as follows to see info about PID 1313
$ pstree 1313
$ pstree -H 1313

In this following example, display only those tree branches (processes) that have been initiated by a user with a username nixcraft:
$ pstree nixcraft

pstree command options

From the pstree(1) command man page:

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

Related media

This tutorials is also available in a quick video format:

See also
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

6 comments… add one
  • Sri Feb 6, 2014 @ 9:23

    Hey all

    PDF file is not displaying the full info provided on this page. Does anyone have the same problem?

    • 🐧 Nix Craft Feb 6, 2014 @ 9:33

      Try again. All pdf files are cached on server to avoid load issues. The latest version will be automatically released after some time.


  • Mladen Feb 6, 2014 @ 10:36

    Great article, useful command.

  • annoyed Nov 17, 2014 @ 17:15

    “To show PIDS for each process name, pass the -p option:
    $ pstree -p”

    yeah, and what exactly does that mean?
    sorry, but this is as braindead as the man page, there’s a slo no expanation — but at least here i would have expected more than “that’s what the parameters look like”

    • E_Cooking Feb 10, 2017 @ 18:06

      A PID (i.e., process identification number) is an identification number that is automatically assigned to each process when it is created on a Unix-like operating system.

      A process is an executing (i.e., running) instance of a program. Each process is guaranteed a unique PID, which is always a non-negative integer.

      The process init or systemd is the only process that will always have the same PID on any session and on any system, and that PID is 1. This is because init/systemd is always the first process on the system and is the ancestor of all other processes.

      So when you pass the -p option you see a PID for each process.

  • E_Cooking Feb 10, 2017 @ 17:55

    What about?
    ps axfj

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.