Skip to Content

3 ways to Find Top CPU-Consuming Processes in Linux

High CPU usage by certain processes can lead to system slowdowns, unresponsiveness, and in some cases, complete halts, making it essential for system administrators and power users to quickly identify and manage such processes.

This article aims to provide readers with practical and easy-to-follow methods to pinpoint the processes that are utilizing the most CPU power on their Linux system.

We will delve into various command-line tools such as top, ps, and htop, each offering its unique approach to process monitoring.

Using the top Command

  1. Open the Terminal: Access your command line interface.
  2. Run the top Command: Type top to open an interactive interface showing system and process statistics.
  3. Sort by CPU Usage: Press Shift + P if needed to sort processes by CPU usage. The interface updates in real-time.
  4. Reading the Output: The top part shows system statistics; the bottom part lists processes. The top 10 CPU-consuming processes are displayed first.
  5. Exiting top: Press q to return to the command line.

 

How to Analyze the ‘top’ Command to Identify Most CPU-Consuming Processes

Understanding the ‘top’ Interface

The top interface is divided into two main sections:

  • Summary Area: Displays system statistics including CPU and memory usage.
  • Task Area: Lists individual processes with various details.

Interpreting the Columns

Focus on the following columns in the task area:

  • PID: Process ID.
  • USER: User running the process.
  • %CPU: Percentage of CPU time used by the process.
  • %MEM: Memory usage by the process.
  • COMMAND: Command that started the process.

Identifying High CPU Processes

Processes are sorted by CPU usage, with the highest at the top. Monitor the %CPU column to see the CPU usage.

Analyzing Process Behavior

Monitor the %CPU column for consistent high usage or spikes. Processes consistently at the top are likely impacting performance.

Additional Features

  • Filter by User: Press u to filter processes by user.
  • Kill a Process: Press k to kill a problematic process.

 

Note: The top command provides real-time data. Some processes may spike in CPU usage temporarily. Continuous high usage is typically more concerning. For a more user-friendly interface, consider using htop.

Using the ps Command

  1. Open the Terminal: Access the command line.
  2. Run the ps Command: Use ps -eo %cpu,pid,command –sort=-%cpu | head -n 11 to list processes with CPU usage.
  3. Understanding the Output: This static snapshot shows CPU usage, process ID, and command line for each process.

 

Breakdown of the Command

  • ps -eo %cpu,pid,command: Displays CPU usage, process ID, and command line for each process.
  • –sort=-%cpu: Sorts the output by CPU usage in descending order.
  • | head -n 11: Limits the output to the top 10 lines, effectively showing the top 10 consuming processes.

 

Interpreting the Output

The command lists the processes using the most CPU resources at the top, with columns for CPU usage, process ID, and the command line.

Note

This command provides a static snapshot at the moment of execution. For real-time monitoring, tools like top or htop are more suitable. The ps command offers various options for output customization for different monitoring needs.

Using htop (If Installed)

  1. Install htop: Use package management commands to install htop if it’s not already installed.
  2. Run htop: Type htop for an interactive, color-coded process view.
  3. Interacting with htop: Processes are sorted by CPU usage; you can scroll and manage processes.
  4. Exiting htop: Press q to exit.

Note: top and htop are ideal for real-time monitoring, while ps captures a specific moment snapshot.

How to fix the issue

  • Understand the process’s role and function.
  • Refer to the process’s documentation for typical CPU usage.

Monitor Process Behavior Over Time

  • Determine if the high CPU usage is consistent or sporadic.
  • Use tools like htop for time-based monitoring.

Investigate Common Causes

  • Check for resource-intensive tasks.
  • Investigate potential application bugs or misconfigurations.
  • Assess system resource limitations.

Check Logs and System Health

  • Review system and application logs for relevant information.

Apply Potential Fixes

  • Update software and applications.
  • Make necessary configuration changes.
  • Optimize application performance or redistribute the workload.