Open In App

pstree Command in Linux with Examples

Last Updated : 03 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Pstree command in Linux that shows the running processes as a tree which is a more convenient way to display the processes hierarchy and makes the output more visually appealing. The root of the tree is either init or the process with the given pid. Pstree can also be installed in other Unix systems.

Syntax:

pstree [options] [pid or username]

Working with Pstree Command

1. To display process tree

pstree

to-display-process-tree

to-display-process-tree1

It produces process-related information in output.

2. To include command line arguments in output

pstree -a

include-cli-argumentes

include-cli-arguments1

We do this by using the “-a” command line option. This command now displays command line options for some processes.

3. To display PIDs

pstree -p

to-display-pid-in-pstree

to-display-pid-in-pstree1

To display PIDs for each process name, we use “-p” option.

4. To force pstree to expand identical subtrees in output.

pstree -c

expand-identical-subtree-pstree1

expand-identical-subtree-pstree

By default, the pstree command merges identical branches by putting them in square brackets and prefixing them with the repetition count. But we can also force the tool to expand identical trees, by using the “-c” command-line option.

5. To sort processes

pstree -n

sort-process-pstree

sort-process

If we want to sort processes with the same ancestor by PID instead of by name i.e. numeric sort, we use “-n” option.

6. To see who is the owner/user of a process

pstree -u

owner-pstree

owner-pstree1

If we want to find out the owner of a process in parenthesis, use the “-u” option.

7. To highlight the current process or any other process

pstree -h

highlight-pstree

highlight-pstree1

To highlight the current process and its ancestors use “-h” option. It highlights the specified process (by name/pid)

8. To show process group IDs in output

pstree -g

display-groupid-pstree

We can see that process group IDs are shown as decimal numbers in parentheses after each process name.

9. To make pstree display process tree specific to a user.

pstree khushi

pstree-specific-to-user

It we want to display all process trees rooted at processes owned by a specific user, for this, we have to pass the name of that user as input to the command.

10. To display version information.

pstree -V

pstree-version

When we want to display version information we use “-V” option.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads