TrumanWong

pstree

Show the derivation relationship between processes in the form of a tree diagram

Supplementary instructions

pstree command displays the derivation relationship between processes in a tree diagram, and the display effect is relatively intuitive.

grammar

pstree(option)

Options

-a: Display the complete instructions of each program, including path, parameters or identification of resident services;
-c: Do not use simplified notation;
-G: Use the column drawing characters of the VT100 terminal;
-h: When listing the tree diagram, specifically indicate the currently executing program;
-H<program identification code>: The effect of this parameter is similar to specifying the "-h" parameter, but specifically identifies the specified program;
-l: Display the tree diagram in long column format;
-n: Sort by program identification code. The default is to sort by program name;
-p: Display program identification code;
-u: Display user name;
-U: Use UTF-8 column drawing characters;
-V: Display version information.

Example

Display the process number and process id of all current processes

pstree -p

Displays all detailed information of all processes, and can compress the display when encountering the same process name.

pstree -a

Get the PID of an SSH session

pstree -p | grep ssh

# |-sshd(1221)-+-sshd(2768)---bash(2770)-+-grep(2810)
# | `-sshd(2807)---sshd(2808)

From the output above, you can see a tree diagram of sshd processes and branches. The main process of sshd is sshd(1221), and the other two branches are sshd(2768) and sshd(2807).