top
Display and manage running processes
TLDR
Start top
Do not show any idle or zombie processes
Show only processes owned by given user
Sort processes by a field
Show the individual threads of a given process
Show only the processes with the given PID(s), passed as a comma-separated list. (Normally you wouldn't know PIDs off hand. This example picks the PIDs from the process name)
Display help about interactive commands
SYNOPSIS
top [options]
PARAMETERS
-b
Batch mode operation. Instead of running interactively, top will output the statistics to standard output.
-c
Toggle the display of command names or full command lines.
-d delay
Specifies the delay between screen updates in seconds. The default is 3 seconds.
-h
Displays help information.
-i
Idle Processes toggle. When enabled idle/zombie processes aren't shown
-n iterations
Specifies the number of iterations top will run before exiting in batch mode.
-p pid
Monitors only processes with specified process ID(s).
-s
Secure mode operation. Disable commands which can potentially compromise the system.
-u user
Monitors only processes with specified username.
-v
Displays version information.
-H
Threads toggle. Display threads as individual processes
-o field
Sort by this field. Use '-o help' to see a list of supported fields.
DESCRIPTION
The top command provides a dynamic real-time view of a running system. It displays a list of processes or threads, ordered by selected criteria (typically CPU usage), and updates the display periodically. It shows a summary of system information, including CPU utilization, memory usage, swap usage, and the number of tasks running. This makes it an invaluable tool for system administrators and developers for identifying resource-intensive processes, diagnosing performance bottlenecks, and understanding the overall health of a Linux system.
The information displayed can be customized through interactive commands allowing users to filter, sort, and display specific data points. While similar tools exist, top's longevity and widespread availability have made it a standard for system monitoring on Linux and other Unix-like operating systems.
CAVEATS
The behavior of top can vary slightly across different Linux distributions and versions. The exact columns and interactive commands available may differ.
INTERACTIVE COMMANDS
While running, top accepts single-character commands to modify its behavior. Common commands include:
k: Kill a process.
h: Display help.
q: Quit.
n: Change the number of processes displayed.
M: Sort by memory usage.
P: Sort by CPU usage.
UNDERSTANDING OUTPUT COLUMNS
Key columns in top's output include:
PID: Process ID.
USER: Username of the process owner.
PR: Priority of the process.
NI: Nice value of the process.
VIRT: Virtual memory used by the process.
RES: Resident memory used by the process.
SHR: Shared memory used by the process.
S: Process state (e.g., sleeping, running).
%CPU: Percentage of CPU time used by the process.
%MEM: Percentage of physical memory used by the process.
TIME+: Total CPU time used by the process.
COMMAND: Command name or full command line.
HISTORY
The top command has a long history, originating in the early days of Unix. It evolved to provide a real-time view of system processes and resource usage, becoming a crucial tool for system administrators to monitor server health and performance. Over time, various versions and implementations of top have emerged, each adding features and improvements to adapt to changing system architectures and monitoring needs. The core functionality, however, remains the same: to provide a dynamic and interactive display of system activity.