Using Linux Pstree to display process parent-child relationship

Updated: Feb 15

Pstree displays the process parent-child relationship in a hierarchical format on Linux. We can use this command to find the parent or child process easily. The output of this command is quite similar to the output of the ps axjf command and the ps -ef --forest command. But pstree result is much easier to understand. Let us start.

Pstree options on Linux

The commonly used options in pstree command are -a -s -p. This will tell us all the related processes. For more options, please check man pstree.

-a     Show command line arguments.  
-s     Show parent processes of the specified process.
-p     Show PIDs.

Use pstree to display the process parent-child relationship

Let us look at an example for this. Now we want to know what is our parent or child process id after we login to our server.

First, we need to get the current shell process id with the command: echo $$

$ echo $$

Second, we can get the parent process id with pstree -asp pid

$ pstree -asp 715
systemd,1 --switched-root --system --deserialize 22
  `-sshd,1680 -D
                  `-pstree,18031 -asp 715

From the output, we can easily see that the parent process id for 715 is 714. The child process id is 18031.

If we want to get all the child processes ids for one specific process, we can also use this command.

bash-4.2$ pstree -asp 519
systemd,1 --switched-root --system --deserialize 22
  `-sshd,1680 -D
                      `-pstree,21090 -asp 519

Related Post:

12 basic Linux commands for Linux beginners


Join our newsletter. Get a free Linux account on Cloud.

Get a Free Cloud Server! 

We can use this cloud server to practice Linux commands. Never miss a post!

Thanks for submitting!