Linux Command Reference ยท Processes and Signals
Linux pstree command
Reference for the Linux pstree command: show parent and child processes as a tree, start from a PID or user, show PIDs and arguments, and read the compressed output.
pstree draws the running processes as a tree: each process is a branch of its parent, so you can see which program started which. It answers questions a flat list from ps makes hard, such as "what does this daemon fork?" or "why does this shell have so many children?".
To keep the tree short, pstree merges identical siblings: 3*[sleep] means three sleep children, and a chain of single children is written on one line with โโโ.
pstree [OPTION]... [PID | USER]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
pstree [-a] [-c] [-h | -H PID] [-l] [-n] [-p] [-s] [-u] [-U] [PID | USER]
| Option | Description |
|---|---|
PID |
Start the tree at this process instead of init or systemd. |
USER |
Show the trees of all processes owned by this user. |
-p |
Show process IDs in parentheses. |
-a |
Show command-line arguments (and implies no merging of different arguments). |
-s |
Show the parents of the chosen process (ancestors). |
-c |
Do not merge identical subtrees. |
-n |
Sort by PID instead of by name. |
-u |
Show user changes, such as (root) at a sudo boundary. |
-l |
Do not truncate long lines. |
-h |
Highlight the current process and its ancestors. |
-H PID |
Highlight the given process. |
-T, -t |
Hide threads (-T) or show thread names (-t). |
-U |
Use UTF-8 line drawing instead of ASCII. |
Returns: 0 on success; 1 if the PID or user does not exist.
Usage notes
- It reads
/proc.pstreeshows what the kernel reports at that instant; a fast-exiting process may not appear. - Brace names
are threads. Use-Tto hide them when counting real processes. - Merged siblings.
2*[ssh]is two identical branches. Use-cto expand them or-pto separate them by PID. - Containers and namespaces. Inside a container,
pstreebegins at PID 1 of that container, not at the host'sinit. - Orphans. If a parent dies, its children are re-parented to PID 1 (or to the nearest subreaper), so the tree shows them there.
- Find the culprit.
pstree -ps PIDshows the whole chain of ancestors of one process, handy to see who launched an unexpected program. - Related counts:
pgrep -P PIDlists direct children only, which is better for scripts than parsing the drawing.