How to Monitor & Optimize CPU and Memory Usage on Linux, Windows, and macOS
Master system performance tuning across Linux, Windows, and macOS using CPU and memory monitoring tools like htop, Task Manager, Activity Monitor, and more.

System performance matters—whether you're running a heavy-duty backend server on Linux, multitasking on Windows, or pushing Xcode to its limits on macOS. You don’t want your laptop sounding like a jet engine or your EC2 instance crashing from an out-of-memory error.
This guide walks you through how to check and analyze CPU and memory usage, interpret the data, and take practical actions across Linux, Windows, and macOS. Let’s dive in.
Linux Performance Monitoring with htop, vmstat & swap tuning
Check CPU and Memory Usage
Linux gives you surgical control via CLI tools. Start with:
-
toporhtop: Real-time usage metricstop sudo apt install htop htop -
ps aux --sort=-%mem: Sorts by memory usageps aux --sort=-%mem | head -n 10 -
free -h: View memory in a human-readable formatfree -h -
vmstat: Shows memory, swap, and CPU context switchingvmstat 1 5
Learn more: Linux Memory Explained
Optimization Tips
-
Enable swap (if disabled) – Many VMs (like EC2) don’t enable swap by default:
sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab -
Tune Java apps (JVM-based) — Limit memory usage:
-Xmx512M -Xms512M
Windows: Task Manager, Resource Monitor & PowerShell Tricks
Check Resource Usage
-
Task Manager (
Ctrl + Shift + Esc):- View CPU usage per core
- Check memory consumption
- Review app/resource breakdowns
-
Resource Monitor:
- From Task Manager > Performance > Open Resource Monitor
- Monitor by process, network, disk, and more
-
PowerShell:
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 Get-Process | Sort-Object WS -Descending | Select-Object -First 10
Learn more: Windows Performance Tuning
Optimization Tips
- Disable startup apps — Uncheck unnecessary ones in the Startup tab
- Enable paging file (virtual memory)
- Remove bloatware — Pre-installed apps often hog memory
macOS: Activity Monitor, Terminal Tools & Optimization
Check Resource Usage
-
Activity Monitor:
- Open via Spotlight (
Cmd + Space> “Activity Monitor”) - Tabs: CPU, Memory, Energy, Disk, Network
- Open via Spotlight (
-
Terminal Tools:
top vm_stat- Get free memory in MB:
pagesize=$(pagesize) vm_stat | awk -v page_size=$pagesize '/Pages free/ {print $3 * page_size / 1024 / 1024 " MB"}'
- Get free memory in MB:
-
ps + sort:ps aux | sort -nrk 3 | head -n 10 # Top CPU ps aux | sort -nrk 4 | head -n 10 # Top Memory
Learn more: Apple Developer Performance Tips
Optimization Tips
- Close idle Chrome tabs — Each one is a separate process
- Purge caches (dev use only):
sudo purge - Reindex Spotlight (if
mdsis hogging CPU):sudo mdutil -E /
Must-Know CPU & Memory Metrics Explained
| Metric | What It Tells You |
|---|---|
| %CPU | Processor usage per task/core |
| RSS (Memory) | Actual RAM used by a process |
| Swap Used | Memory overflow – indicates stress |
| Load Average | Average system load (Linux) |
| Memory Pressure | RAM strain (macOS) |
Best Cross-Platform Tools for Monitoring
- Glances: All-in-one CLI monitor →
pip install glances
Glances GitHub - Netdata: Live dashboards → Netdata Cloud
- Grafana + Prometheus: For full observability
Grafana Docs - Process Explorer: Windows power tool → Microsoft Sysinternals
Common Symptoms & Quick Fixes
| Symptom | Quick Fix |
|---|---|
| High memory, no swap | Enable swap (Linux) / Check paging (Win) |
| JVM app using too much RAM | Limit heap: -Xmx512M |
| Chrome eating RAM | Close tabs, use Safari (macOS) |
| Random CPU spikes (Mac) | Reindex Spotlight |
| Background process bloat | Use ps, top, or Task Manager |
Final Thoughts
System performance isn’t just about uptime — it’s about user experience, developer productivity, and infrastructure cost. The key is to observe patterns, know what “normal” looks like, and take action before things go south.
Whether you're debugging a dev laptop or running a multi-node Kubernetes cluster, these tools and tips will help you stay fast and lean.
Nife.io makes multi-cloud infrastructure and application orchestration simple. It provides enterprises with a unified platform to automate, scale, and manage workloads effortlessly.
Discover how Nife streamlines Application Lifecycle Management.
Deploy on Nife
Ready to deploy? Check out the Nife documentation:
From the team at Nife
Deploy your next app in minutes, not days.
Nife is a multi-cloud edge platform that lets you deploy, scale, and manage applications globally without the infrastructure headache.