📊 Commands: top & htop (Process Management)
These commands are the "Task Manager" of the Linux world. They allow you to see what your computer is doing in real-time, which apps are using the most CPU, and how much RAM is left.
1. The "Why"
On a system like Arch Linux, especially when running resource-heavy environments like Hyprland or compiling Java code in VS Code, you need to monitor your resources.
- Identify "Zombie" processes: Find apps that are stuck and eating up CPU.
- Monitor RAM: See if your Gradle builds or Android emulators are pushing your system to its limits.
- Kill unresponsive apps: Stop a process that has frozen your UI without rebooting the whole machine.
2. top (The Classic)
top is the "Table of Processes." It is installed by default on almost every Linux system in existence.
- Look: It is plain text and black-and-white.
- Function: It provides a list of processes that refreshes every few seconds.
- Key Info:
- %CPU: How much processing power a task is using.
- %MEM: How much RAM is being used.
- RES: The actual physical memory the process is using.
- COMMAND: The name of the program.
3. htop (The Modern Interactive Version)
htop is like top but on steroids. It is much more user-friendly, colorful, and interactive. (Note: On Arch, you might need to install it first: sudo pacman -S htop).
- Visual Meters: It shows CPU cores, RAM, and Swap as visual bars at the top.
- Mouse Support: You can actually click on things in most terminal emulators.
- Easy Actions: The function keys (F1-F10) at the bottom allow you to search, filter, and kill processes easily.
4. How to Read the Output
Both tools show a few critical values you should know:
- Load Average: Three numbers representing the system load over the last 1, 5, and 15 minutes. If these numbers are higher than your number of CPU cores, your system is struggling.
- PID (Process ID): The unique ID number for every running program. You need this number if you want to manually "kill" a process.
- VIRT vs RES: VIRT is how much memory the app thinks it has access to; RES is what it is actually using right now.
5. Essential Controls
| Key | Action (in top) |
Action (in htop) |
|---|---|---|
| q | Quit | Quit |
| k | Kill a process (enter PID) | Kill (opens a menu) |
| M | Sort by Memory usage | (Use F6 to sort) |
| P | Sort by CPU usage | (Default) |
| u | Filter by User | Filter by User |
| F10 | — | Exit safely |
6. Pro-Tips
- The "Kill" Signal: When you kill a process in
htop(F9), it asks which signal to send. SIGTERM (15) is a polite "Please close." SIGKILL (9) is a "Die immediately" command for frozen apps. - Tree View: In
htop, press t to see the "Tree View." This shows you which processes started which (e.g., you can see which specific plugin is making VS Code slow). - Arch Linux Context: If your Hyprland workspace starts lagging, open
htopto see if a background process (like a waybar script or a heavy browser tab) is spiking your CPU.
7. Summary Reference
| Goal | Command |
|---|---|
| Quick system check | top |
| Interactive management | htop |
| Kill a frozen app | htop → Select → F9 → Enter |
| Check only your processes | htop -u $USER |