Instructions for using pstree command on Linux

Pstree is a powerful and useful command to display processes running in Linux. Like the ps command, it shows all the processes that are currently active on your login system. The main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command. This tree displays processes in a parent-child relationship. The parent process is the process of creating all child processes below it.

The pstree pf structure is similar to the hierarchical directories on Unix systems like Linux and macOS. Using this structure, you can quickly navigate through the process tree to see which processes create or control each other, allowing the exact removal of processes that cause problems or are not controlled by the kill command. .

Run the command pstree

To run the basic form of this command, open the Terminal window and type the following command, then press Enter :

 pstree 

Instructions for using pstree command on Linux Picture 1

This command will display a list of all processes running on the system. The top process (in this case, systemd) is the parent process. The processes below it are created or opened via systemd. And branches from these processes show similar relationships, like family trees.

Here is the basic structure of pstree:

 parent ———— child (1) ———— subchild (1) | | --subchild (2) | | -child (2) 

By default processes generated from the same parent process will be ordered alphabetically. There are many other ways to sort in pstree using flags, we will discuss below.

Use pstree with flags

Like most Terminal programs, pstree can combine with different flags to create more complex output. To display process identification information, you can use the -p flag, display process identification number or PID.

 pstree -p 

Instructions for using pstree command on Linux Picture 2

You can sort progress by PID instead of name with -n flag.

 pstree -np 

Instructions for using pstree command on Linux Picture 3

You may have noticed, the pstree output is usually cut off at the terminal window. Therefore, you can 'pack' long result lines with the - l flag.

 pstree -l 

Instructions for using pstree command on Linux Picture 4

However, this operation will make it difficult for users to read the output.

See also: Store the output of a Linux command into a file

Show parts of the process tree

You can also view only a part of the process tree. There are two ways to do this. First, use the -s flag, allowing you to see the parent process of the child process you specify. You can call this process by its PID.

 pstree -s 780 

Instructions for using pstree command on Linux Picture 5

You can also view processes generated by the current user. If there are multiple users on the system, you will know who is doing what on your system. To see the processes generated by the user, just type the user name after the main command.

 pstree alexander 

This command will display any commands executed by that user's account, via the user program run or through the command they execute.

Each version of Linux may have different ways to use this command, but this is the most basic guide. To get help with the version you are using, type man pstree in the command line and press Enter to open the instruction page.

I wish you all success!

See more:

  1. Basic Linux commands everyone needs to know
  2. Certain deadly commands never run on Linux
  3. Guide to network operation for Linux users: 11 commands to know
3.9 ★ | 17 Vote

May be interested

  • How to use ss command on LinuxHow to use ss command on Linux
    the ss command is a new alternative to the classic netstat. you can use it on linux to get data about network connections. here's how to work with this helpful tool.
  • 11 uses of ps command in Linux11 uses of ps command in Linux
    for system administrators, ps is a frequently used tool. the ps command is used to list the processes currently running on the system, with many available filtering and display modes via flags and arguments.
  • How to limit access to su command in LinuxHow to limit access to su command in Linux
    if you have added linux to your data center or are just using a single linux machine for your business, you need to make sure it is as secure as possible.
  • 12 things Linux is easier to do in the command line than graphical software12 things Linux is easier to do in the command line than graphical software
    graphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.
  • 11 df commands in Linux (with example)11 df commands in Linux (with example)
    with the df command in linux, you can easily check your system for details about disk space and file size. these 12 examples of df commands will show you how to do them in detail.
  • How to use the Linux command line on Android with TermuxHow to use the Linux command line on Android with Termux
    android is a very operating system 'capacity with more and more desktop accessibility applications. however, sometimes you want to make some things on android that can be as easy as desktop. fortunately, you can use the termux tool, which builds on the existing infrastructure and provides a command line environment that allows you to install real linux applications on your android device.
  • How to use the history command in LinuxHow to use the history command in Linux
    as you spend more and more time in terminal sessions, you will constantly find new commands that make everyday tasks more efficient. the gnu history command is one of them.
  • The dd command in Linux, How to use the dd commandThe dd command in Linux, How to use the dd command
    dd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.
  • Instructions for using dpkg command on Linux DebianInstructions for using dpkg command on Linux Debian
    this article will talk about the basics of package management in debian and how to manage software packages using the dpkg command.
  • Use the Top command to see the processes running in LinuxUse the Top command to see the processes running in Linux
    the top command in linux is used to display all processes running in the linux environment. this tutorial shows you how to use the top command through explaining the various parameters available and the content they display.