Processes
pstree
Display a tree of running processes.
Additional Notes
pstree displays running processes as a tree structure, showing parent-child relationships. The root of the tree is typically systemd (or init on older systems), with branches showing spawned child processes and threads.
The tree view makes it easy to understand process hierarchies at a glance. It reveals which processes launched which others, helps identify orphaned processes, and shows the structure of complex applications like web servers and container runtimes that fork many children.
Syntax
pstree [options] [pid-or-user]
Parameters
pid-or-user: Show the tree starting from a specific PID, or show all trees for processes owned by a specific user.
Common Options
-p,--show-pids: Show PIDs in addition to process names.-n,--numeric-sort: Sort output by PID number instead of alphabetically.-a,--arguments: Show command-line arguments.-A: Use ASCII characters for tree drawing.-G: Use VT100 line-drawing characters.-U: Use UTF-8 (Unicode) line-drawing characters.-h,--highlight-all: Highlight the current process and its ancestors.-H pid: Highlight the specified PID and its ancestors.-l,--long: Do not truncate long lines.-s,--show-parents: Show parent processes of the specified PID.-S,--ns-changes: Show namespace changes (useful for containers).-t,--thread-names: Show thread names.-T,--hide-threads: Hide threads (show only processes).-u,--uid-changes: Show UID transitions.-Z,--security-context: Show SELinux security context.-g: Show process group IDs.-c: Disable compact mode (shows all children separately).--color: Colorize output by process age or attributes.
Examples
pstree
Show the full process tree.
pstree -p
Show process tree with PIDs.
pstree -a
Show process tree with command-line arguments.
pstree -p 1234
Show the tree rooted at PID 1234.
pstree username
Show all processes owned by a specific user.
pstree -pan 1
Show the full tree from init/systemd with PIDs and arguments, sorted numerically.
pstree -s 1234
Show only the parent chain of PID 1234.
pstree -S $(pidof docker)
Show process tree with namespace changes for Docker.
pstree -p -h 1234
Show the tree and highlight PID 1234.
Practical Notes
- The process tree starts at PID 1 (
systemdorinit). Zombie and orphaned processes appear without proper parents. - Use
pstree -pwhen you need to find a specific PID. Pipe togrepfor searching. - Threads are shown inside curly braces
{thread_name}. Use-Tto hide threads. - The
-soption is useful for finding the parent chain of a problematic process. - For containers,
-Sshows which processes are in different namespaces, helping identify container boundaries. pstreeis part of thepsmiscpackage (ps,pstree,killall,fuser,prtstat).