pstree
Display processes as a tree
TLDR
Display a tree of processes
Display a tree of processes with PIDs
Display all process trees rooted at processes owned by specified user
SYNOPSIS
pstree [options] [pid | username]
PARAMETERS
-p
Show PIDs. Numeric pids are displayed with each process.
-u
Show user names. User names are shown beside each process.
-a
Show command line arguments. The complete command line is shown, rather than just the program name.
-c
If possible, don't compact children of the same process into one line.
-n
Sort processes with the same parent by PID numerically.
-h
Highlight the current process or one of its ancestors.
-G
Use VT100 line drawing characters.
-U
Use UTF-8 (Unicode) line drawing characters.
-A
Use ASCII line drawing characters.
-l
Display long lines. By default, lines are truncated to fit within the screen width.
-V
Display version information.
[pid]
Start the tree at the specified process ID. If not specified, the tree starts at the init process (PID 1).
[username]
Show only the processes owned by the specified user.
DESCRIPTION
The pstree command is a Linux utility that displays running processes as a tree diagram. This hierarchical representation clearly shows parent-child relationships between processes, making it easier to understand process execution flow and identify the origin of processes. It shows the process ID (PID) of each process by default; options can be used to display other information. It provides a simple way to understand how processes are forked and managed by the operating system.
Unlike the `ps` command, which lists all processes, pstree focuses on the relationships between them. This is particularly useful for debugging and system administration, allowing users to quickly identify which process spawned another and trace process ancestry. The tree structure is built based on the PID and PPID (parent process ID) information maintained by the Linux kernel.
CAVEATS
The accuracy of the tree depends on the current state of the process table. Rapidly changing processes may lead to a slightly inaccurate view.
EXAMPLES
- Show the process tree with PIDs: pstree -p
- Show the process tree with usernames: pstree -u
- Show the process tree for a specific user: pstree username
EXIT STATUS
pstree exits with status 0 if successful, and a non-zero value if an error occurs.
HISTORY
The pstree command has been a part of various Unix-like operating systems for many years, evolving to provide a more user-friendly view of process relationships than simply listing processes. It's a tool commonly used by system administrators for understanding system behavior and debugging process management issues. It has been around for as long as process table functionality has been implemented in different Unix OS implementations.