After you’ve had your Raspberry Pi for a while and you’ve made it run a web server, media centre, Remote Desktop and more, you might find it’s becoming a bit sluggish. To diagnose performance issues and identify resource-hungry processes, there’s a brilliant tool called htop that can help.
Understanding System Performance
Traditionally in Linux, you would use the top
command to view system processes and resource usage. However, this generally needs a bit more know-how to interpret the display, and it looks rather plain and difficult to parse at a glance.
Introducing Htop: A Better Process Viewer
An ideal replacement for top
is ‘htop’, developed by Hisham Muhammad. This is an excellent process viewer with simple colour coding and a graphical output to show where resources might be used. Here’s a sample screenshot from my Pi:
htop – a process viewer for the Raspberry Pi
Installing Htop on Your Raspberry Pi
Installation is straightforward. Simply open a terminal and enter:
sudo apt-get update sudo apt-get install htop
That’s it! It’s extremely easy to install and has no real overhead when running, making it suitable even for resource-constrained devices like the Raspberry Pi.
Understanding the Htop Display
CPU Usage
At the top of the display, the numbers 1, 2, 3, 4 represent each processor core’s status (for multi-core models like the Raspberry Pi 4; older models will show fewer cores). The more a core is in use, the further the corresponding graph extends to the right. Different colours indicate different types of processes:
- Blue: Low-priority processes
- Green: Normal user processes
- Red: Kernel processes
Memory Usage
The Mem/Swp bars show the utilisation of your RAM and Swap space:
- RAM (Memory): Linux typically fills RAM for caching, so seeing high utilisation isn’t necessarily a problem. What’s important is the breakdown of used versus cached memory.
- Swap: This is virtual memory on your SD card. Your swap should not be used too much—if it is, your system will often slow down as it swaps memory between the disk (or SD card) and RAM as required. Heavy swap usage is a key indicator that you need more physical RAM or need to reduce your workload.
Process List
The main section displays all running processes with details like:
- PID (Process ID)
- User (who owns the process)
- Priority (PR) and Nice values (NI)
- Virtual (VIRT), Resident (RES), and Shared (SHR) memory usage
- CPU% and MEM% (percentage of CPU and memory used)
- Time (how long the process has been running)
- Command (what program the process is)
Running and Using Htop
Running htop is simple—just log in to the command line (via SSH or local terminal) and type:
htop
Useful Controls and Features
Htop offers many useful features through function keys:
- F1: Help
- F2: Setup (customise the display)
- F3: Search for a process
- F4: Filter processes by name
- F5: Tree view (show parent-child relationships)
- F6: Sort by a column
- F7/F8: Decrease/increase process priority (nice value)
- F9: Kill a process (useful for terminating unresponsive applications)
- F10: Quit
You can also use traditional keyboard shortcuts like Ctrl+M to sort by memory usage or Ctrl+P to sort by processor usage.
Customising Htop
Using F2, you can access the setup menu to add more charts to the top section—on both left and right sides. Don’t forget to save your new default settings for future sessions.
This customisation allows you to focus on the metrics most relevant to your specific use case, whether that’s network I/O, memory breakdown, or CPU load averages.
Identifying Performance Issues
When diagnosing why your Raspberry Pi is running slowly, look for:
- Processes with high CPU usage (near 100% consistently)
- High swap usage (indicating memory pressure)
- Processes consuming large amounts of memory
- Many zombie processes (may indicate underlying issues)
Once you’ve identified problematic processes, you can decide whether to:
- Kill unnecessary processes
- Optimise applications
- Reduce the services running simultaneously
- Consider a hardware upgrade if possible
Availability on Other Linux Systems
If you use another flavour of Linux, it most likely has htop available as well. On CentOS-based systems, try:
yum install htop
Conclusion
Htop is an invaluable tool for monitoring and managing your Raspberry Pi’s performance. With its intuitive interface and detailed information, you can quickly identify what might be causing your Pi to slow down and take appropriate action to optimise its performance.
Regular monitoring with htop can help you maintain a smoothly running system by identifying issues before they significantly impact performance, making it an essential addition to any Raspberry Pi enthusiast’s toolkit.