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 change Google DNS on LinuxPhoto of How to change Google DNS on Linux
    in the previous article, tipsmake.com showed you how to change google dns on a mac. today, let's find out how to change dns on linux and its distributions.
  • How to install ownCloud on LinuxPhoto of How to install ownCloud on Linux
    cloud storage must not be unfamiliar, but have you ever thought you could create your own archives? this article will show you how to create private cloud storage using owncloud application on linux.
  • How to create a Live CD Linux discPhoto of How to create a Live CD Linux disc
    a live cd is a bootable cd, dvd or usb drive with an operating system ready to run when the disc is inserted into the computer. this article will show you how to create a linux live cd.
  • Fix Windows and Linux errors showing different time at dual bootPhoto of Fix Windows and Linux errors showing different time at dual boot
    when booting windows and linux, you may notice that it is not possible to synchronize the system clock between these two operating systems. this is because these two operating systems use different timing methods. this article will show you how to fix windows and linux errors showing different time at dual boot.
  • How to install Steam in UbuntuPhoto of How to install Steam in Ubuntu
    steam is the most popular online gaming platform for pc and linux. there are over 2000 steam games available for linux. although steam is available through the official ubuntu repositories, many new linux users still have trouble installing.
  • Convert data, applications from Windows to Linux in minutesPhoto of Convert data, applications from Windows to Linux in minutes
    many people want to use both windows and linux operating systems that perform dual booting, but recently a problem with windows drivers has made users frustrated and annoyed, so they can only use linux operating system.