1 post tagged with "system monitoring"

View All Tags

How to Monitor & Optimize CPU and Memory Usage on Linux, Windows, and macOS

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#

Linux user monitoring CPU usage using terminal commands like htop

Check CPU and Memory Usage#

Linux gives you surgical control via CLI tools. Start with:

  • top or htop: Real-time usage metrics

    top
    sudo apt install htop
    htop
  • ps aux --sort=-%mem: Sorts by memory usage

    ps aux --sort=-%mem | head -n 10
  • free -h: View memory in a human-readable format

    free -h
  • vmstat: Shows memory, swap, and CPU context switching

    vmstat 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#

Windows user analyzing memory usage with Task Manager and PowerShell

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#

macOS user using Activity Monitor and Terminal tools to monitor RAM

Check Resource Usage#

  • Activity Monitor:

    • Open via Spotlight (Cmd + Space > “Activity Monitor”)
    • Tabs: CPU, Memory, Energy, Disk, Network
  • 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"}'
  • 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 mds is hogging CPU):
    sudo mdutil -E /

Must-Know CPU & Memory Metrics Explained#

MetricWhat It Tells You
%CPUProcessor usage per task/core
RSS (Memory)Actual RAM used by a process
Swap UsedMemory overflow – indicates stress
Load AverageAverage system load (Linux)
Memory PressureRAM strain (macOS)

Best Cross-Platform Tools for Monitoring#


Common Symptoms & Quick Fixes#

SymptomQuick Fix
High memory, no swapEnable swap (Linux) / Check paging (Win)
JVM app using too much RAMLimit heap: -Xmx512M
Chrome eating RAMClose tabs, use Safari (macOS)
Random CPU spikes (Mac)Reindex Spotlight
Background process bloatUse 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.