pstree Command in Linux: View the Process Tree Hierarchy
Learn pstree command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
10 min read
Learn pstree command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What pstree Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
The pstree command in linux provides system administrators and engineers with an intuitive visual map of operating system execution hierarchy. In modern multi-core Linux systems where microservices, container runtimes, background worker pools, and asynchronous daemons spawn hundreds of sub-processes and worker threads, flat tabular listings generated by ps or top obscure which parent process owns which children.
The pstree command in Linux displays currently running processes as a visual, hierarchical tree diagram illustrating parent-child relationships rooted at PID 1 (systemd or init). By grouping duplicate branches, displaying Process IDs (PIDs), and expanding lightweight thread pools, pstree provides an instant, structured overview of process lineage that is significantly easier to interpret than flat tabular outputs from ps or top.
Packaged in the essential psmisc suite alongside fuser and killall, pstree traverses the Linux kernel's virtual process filesystem (/proc) to assemble an in-memory directed tree. It links each process back to its Parent Process ID (PPID), visually branching from the initial supervisor process (typically systemd as PID 1) down to terminal emulators, SSH sessions, web server workers, and utility commands.
Whether you are investigating orphaned zombie processes, identifying runaway thread pools, auditing privilege transitions across user accounts, or determining which supervisor daemon must be restarted to cycle a fleet of stuck worker units, pstree offers the clarity needed for decisive system administration.
What pstree Does and When to Use It
Under the hood, pstree scans all numeric directories inside the /proc filesystem (representing active PIDs). For each process, it reads /proc/[pid]/stat to extract the executable name, state, and Parent Process ID (PPID, field 4), reads /proc/[pid]/status to identify effective User IDs (UIDs), and reads /proc/[pid]/cmdline to obtain the full command-line arguments. To track multi-threaded applications, pstree inspects /proc/[pid]/task/, which lists the thread IDs (TIDs) of all Lightweight Processes (LWPs) sharing the same memory address space and file descriptor table.
After harvesting these records, pstree constructs an n-ary tree data structure in memory. It identifies the root of the tree (PID 1) and recursively sorts child nodes lexicographically or numerically. To conserve terminal screen space, pstree automatically consolidates identical child branches into a single summarized node (for example, displaying 4*[nginx] instead of four identical lines) unless the -c (compact disabled) flag is explicitly passed.
Under the hood, pstree gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as -p, -a, -u, -c turns raw process and service tables into actionable diagnostics during incident response.
Availability and Installation Across Linux Distributions
The pstree utility is packaged in psmisc across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether pstree is installed and inspect which binary path and version your shell resolves:
type -a pstree
pstree --version 2>/dev/null || man -f pstree
# Illustrative output (reviewed against documentation)
pstree is /usr/bin/pstree
pstree (psmisc)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y psmisc
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y psmisc
# Arch Linux
sudo pacman -S --noconfirm psmisc
# Alpine Linux
sudo apk add --no-cache psmisc
Command Syntax, Arguments, and Exit Status Codes
pstree [OPTIONS] [PID | USER]
The command synopsis is elegant: pstree [OPTIONS] [PID | USER]. Invoking pstree without arguments prints the complete tree rooted at PID 1. If an optional PID argument is provided, pstree prunes the display and shows only the subtree rooted at that specific process. If a USER argument is specified, pstree prints all subtrees containing processes owned by that user account.
Key command-line options include -p to append the Process ID in parentheses after each process name, -a to display the full command-line arguments including interpreted script paths, -u to show user ownership transitions whenever a child process drops privileges, -T (or -t) to hide or show lightweight threads, and -h (or -H <PID>) to highlight the current process or a specific target PID in bold or reverse video.
0— Successful execution; the process tree was constructed and rendered to stdout.1— Operational error, such as specifying an invalid or non-existent PID or username argument.2— Invalid command-line option or unparseable syntax flag.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
-p | --show-pids | Displays Process IDs (PIDs) in parentheses beside each process name in the tree. |
-a | --arguments | Shows command-line arguments for each process, wrapping long lines cleanly. |
-u | --uid-changes | Shows user account name transitions whenever a process runs under a different UID than its parent. |
-c | --compact-not | Disables branch compaction, displaying every identical child process on its own line. |
-h | --highlight-all | Highlights the current process and its ancestor chain in the terminal. |
-H <pid> | --highlight-pid=<pid> | Highlights the specified PID and its lineage in bold terminal formatting. |
-T | --hide-threads | Hides lightweight threads, showing only true independent processes. |
-s | --show-parents | Shows only the parent chain leading up to the specified PID or process. |
-g | --show-pgids | Displays Process Group IDs (PGIDs) instead of standard process names. |
In day-to-day administration, combining pstree -p is standard practice because seeing the PID in parentheses allows immediate handoff to kill, strace, or systemctl. Adding -a (e.g. pstree -pa) is invaluable when inspecting interpreted language runtimes (such as Python, Node.js, or Ruby) where every process appears as python3 or node unless arguments reveal the script path.
When debugging multi-threaded daemons, the default behavior of pstree shows threads enclosed in curly braces (e.g. {pool}). Passing -T suppresses these threads to reveal the clean process architecture, while omitting -T lets you audit whether an application is leaking hundreds of idle worker threads.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. Display the Full System Process Tree with PIDs
Render the complete system process hierarchy showing every process and its numeric Process ID (PID).
pstree -p
# Illustrative output (reviewed against documentation)
systemd(1)─┬─accounts-daemon(842)─┬─{gdbus}(849)
│ └─{gmain}(846)
├─cron(856)
├─dbus-daemon(857)
├─nginx(1420)─┬─nginx(1421)
│ └─nginx(1422)
├─sshd(920)───sshd(14502)───bash(14520)───pstree(14610)
└─systemd-journal(412)
pstree illustrates the complete ancestry from systemd (PID 1) through sshd and bash down to the currently executing pstree command.
2. Inspect a Specific Subtree with Full Command-Line Arguments
Prune the tree to inspect only a specific service tree (e.g. Nginx or PostgreSQL) while displaying full command arguments.
pstree -pa 1420
# Illustrative output (reviewed against documentation)
nginx,1420 -g daemon on; master_process on;
├─nginx,1421 -g daemon on; master_process on;
└─nginx,1422 -g daemon on; master_process on;
Targeting PID 1420 isolates the master Nginx process and its worker processes while displaying the complete configuration flags (-g).
3. Show Process Ancestry Leading Up to a Specific Process
Use the -s option to inspect the lineage chain from PID 1 directly to a given process ID, ignoring unrelated branches.
pstree -s -p 14520
# Illustrative output (reviewed against documentation)
systemd(1)───sshd(920)───sshd(14502)───bash(14520)
The -s flag prints only the direct parent lineage, revealing that bash (14520) was spawned by sshd child (14502) under sshd daemon (920).
4. Highlight User ID Transitions Across Child Processes
Identify where processes drop root privileges or transition to dedicated service accounts using -u.
pstree -u -p 1420
# Illustrative output (reviewed against documentation)
nginx(1420)─┬─nginx(1421,www-data)
└─nginx(1422,www-data)
The -u flag indicates that while the master process (1420) runs as root, worker processes (1421, 1422) transitioned to the unprivileged www-data user.
5. Filter the Process Tree by Username
Display only processes and execution chains associated with a specific user account.
pstree -p postgres
# Illustrative output (reviewed against documentation)
postgres(1102)─┬─postgres(1104)
├─postgres(1105)
└─postgres(1106)
Filtering by the username 'postgres' displays only the PostgreSQL master daemon and its background worker sub-processes.
6. Suppress Lightweight Threads to View Pure Processes
Use -T to hide thread groups ({thread}) and display only true fork-level child processes.
pstree -T -p
# Illustrative output (reviewed against documentation)
systemd(1)─┬─dockerd(1250)───containerd(1310)
├─mysqld(1402)
└─sshd(920)───sshd(14502)───bash(14520)
Hiding threads simplifies multi-threaded services like mysqld and dockerd down to their single master process entries.
Real-World Workflows, Pipelines, and Shell Automation
Tracing Orphaned Worker Daemons and Zombie Process Parentage
When an application leaks processes or leaves defunct zombie processes ([zombie] <defunct>) in the system table, use pstree to identify the neglecting parent.
#!/usr/bin/env bash
set -euo pipefail
echo "=== 1. Checking for defunct/zombie processes ==="
ZOMBIES=$(ps -eo pid,ppid,stat,comm | awk '$3 ~ /^Z/ {print $1}')
if [ -z "${ZOMBIES}" ]; then
echo "No zombie processes detected on system."
else
for ZPID in ${ZOMBIES}; do
echo "Zombie PID: ${ZPID}"
echo "Lineage chain to responsible parent process:"
pstree -s -p "${ZPID}"
done
fi
# Illustrative output (reviewed against documentation)
=== 1. Checking for defunct/zombie processes ===
Zombie PID: 18452
Lineage chain to responsible parent process:
systemd(1)───supervisord(980)───gunicorn(18400)───python3(18452)
pstree -s -p quickly confirms that gunicorn (PID 18400) failed to reap its child worker (18452), identifying which supervisor must be reloaded.
Inspecting Multi-Threaded Application Concurrency and Thread Pools
Audit an application's thread allocation under production load to verify whether worker pools are operating within concurrency limits.
#!/usr/bin/env bash
set -euo pipefail
APP_NAME="redis-server"
PID=$(pgrep -f "${APP_NAME}" | head -n 1)
if [ -z "${PID}" ]; then
echo "Application ${APP_NAME} not currently running."
exit 1
fi
echo "Inspecting process tree and active thread pool for ${APP_NAME} (PID: ${PID}):"
pstree -p -a "${PID}"
THREAD_COUNT=$(ls -1 /proc/"${PID}"/task | wc -l)
echo "Total kernel threads active: ${THREAD_COUNT}"
# Illustrative output (reviewed against documentation)
Inspecting process tree and active thread pool for redis-server (PID: 1042):
redis-server,1042 /etc/redis/redis.conf
├─{bio_close_file},1043
├─{bio_aof_fsync},1044
├─{bio_lazy_free},1045
└─{io_thd_1},1046
Total kernel threads active: 5
pstree reveals each background thread name (bio_close_file, bio_aof_fsync) inside curly braces, confirming that Redis asynchronous I/O threads are active.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding pstree inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
The pstree command is strictly a read-only diagnostic utility and does not alter system state. However, administrators frequently use pstree output to locate process trees for batch termination (e.g. kill $(pgrep ...)). Caution must be taken not to target a top-level supervisor (such as systemd, containerd, or supervisord) which would recursively destroy all dependent production workloads.
pstree relies on reading process metadata from /proc. On hardened Linux systems where /proc is mounted with the hidepid=2 option, unprivileged users cannot see processes belonging to other users. In this security configuration, running pstree as an unprivileged user displays only the user's own processes and branches; full system visibility requires sudo or membership in an authorized audit group.
Passing the -a (arguments) option causes pstree to read and display /proc/[pid]/cmdline. If third-party scripts or applications improperly accept database passwords, API keys, or private tokens via command-line flags rather than environment variables or secret vaults, these credentials will be displayed in plaintext. Care should be exercised when sharing pstree output in ticket systems or incident reports.
GNU/Linux, BSD, and BusyBox Implementation Differences
The standard pstree utility on Linux is maintained by the GNU psmisc project. On BSD systems (FreeBSD, OpenBSD) and macOS, a different port of pstree exists which uses slightly different command-line switches (for example, using -w for wide output).
On minimal Linux installations or BusyBox containers where psmisc is not installed, you can generate an equivalent hierarchical process tree using standard POSIX ps flags supported by procps: ps -ef --forest or ps axjf.
Troubleshooting Common Errors and Diagnostics
pstree: command not found
Root Cause: The psmisc package containing pstree is not installed by default on minimal Linux server images and containers.
Resolution: Install the psmisc package using your distribution package manager.
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y psmisc
# RHEL / Rocky / Fedora
sudo dnf install -y psmisc
Tree lines appear as garbled characters (e.g. âââ instead of ───)
Root Cause: The terminal emulator or SSH client is not configured for UTF-8 character encoding, corrupting VT100 box-drawing characters.
Resolution: Force classic ASCII tree lines by passing the -A flag or export LC_ALL=C.UTF-8.
pstree -A -p
# Or configure terminal encoding:
export LC_ALL=en_US.UTF-8
Only personal processes appear; other system services are missing
Root Cause: The kernel /proc virtual filesystem is mounted with the hidepid=1 or hidepid=2 hardening option.
Resolution: Run pstree with sudo to grant read permissions to all /proc/[pid] directories.
sudo pstree -p
Alternatives, Related Commands, and Related Tutorials
- ps Command in Linux: ps aux, ps -ef, Custom Columns, and Sorting — Practical syntax, flags, and examples for
ps. - top Command in Linux: Monitor CPU, Memory, and Processes in Real Time — Practical syntax, flags, and examples for
top. - How to Kill a Process in Linux: kill, killall, and pkill Guide — Practical syntax, flags, and examples for
kill. - pidof Command in Linux: Find Process IDs by Program Name — Practical syntax, flags, and examples for
pidof. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!