You can monitor CPU usage in Linux using various tools and commands. Here are some popular options:
1. Top Command
The top command provides a real-time view of your system's processes, including CPU usage.
- Run the command:
top
- Key information:
- CPU Usage: Displays the overall CPU usage, broken down by user, system, nice, idle, and other processes.
- Processes: Lists the running processes, sorted by CPU usage by default.
- Navigation: Use the arrow keys to navigate, press
q
to quit.
2. htop Command
htop is an interactive process viewer that provides a more user-friendly interface than top
.
- Run the command:
htop
- Key features:
- Color-coded display: Provides a visual representation of CPU usage.
- Process filtering: Allows you to filter processes based on name, user, or other criteria.
- Interactive mode: Allows you to kill processes, change process priorities, and more.
3. ps Command
The ps command provides information about running processes. You can use specific options to display CPU usage.
- Run the command:
ps -aux --sort=-%cpu
- Key information:
- %CPU: Displays the CPU usage percentage for each process.
- PID: The process ID.
- USER: The user who owns the process.
- COMMAND: The command that started the process.
4. mpstat Command
The mpstat command provides detailed CPU statistics, including per-CPU usage.
- Run the command:
mpstat -P ALL 1
- Key information:
- CPU: Displays the CPU usage for each core.
- %usr: User time.
- %sys: System time.
- %idle: Idle time.
5. System Monitor (Graphical Interface)
Most Linux distributions include a system monitor tool that provides a graphical representation of CPU usage.
- Example: GNOME System Monitor (Ubuntu, Fedora, etc.)
- Open the tool: Search for "System Monitor" in the application menu.
- View CPU usage: The system monitor typically displays CPU usage in a graph or bar chart.
These tools and commands can help you monitor and understand your system's CPU usage. You can choose the method that best suits your needs and preferences.