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 mail group. Get a free Linux account on Cloud.

Never miss a post!

Want a free Linux account?  This account can be used to login to our cloud server and practice Linux commands.


✔ Linux Commands   ✔ Linux Skills    ✔ LinuxPerformance   ✔ Linux Interview

Some articles are from the public internet. If you find your article misused or undesired here and you don't want us to display it, please let us know and we'll remove it immediately.