Script Valley
Linux & Bash for Developers
Process Management & System MonitoringLesson 4.3

How to monitor CPU and memory usage in Linux

top, htop, ps aux sorting, free command, vmstat, uptime, load average, memory types RSS VSZ, /proc filesystem

top and htop Are Your System Dashboard

top is a live view of system resource usage. It refreshes every few seconds showing CPU, memory, and per-process stats. htop is an improved version with color and mouse support โ€” install it with your package manager.

Key Metrics to Watch

Load average (shown in uptime and top header) is the average number of processes waiting to run. On a 4-core system, a load of 4.0 means fully loaded but not overloaded. Load of 8.0 means processes are queuing. RSS (Resident Set Size) is actual RAM a process uses. VSZ is virtual memory including mapped files โ€” RSS is what matters for real usage.

# Live system overview (q to quit, k to kill a process)
top

# Sort by memory in top: press Shift+M
# Sort by CPU in top: press Shift+P

# Non-interactive: top 5 memory consumers
ps aux --sort=-%mem | head -6

# Non-interactive: top 5 CPU consumers
ps aux --sort=-%cpu | head -6

# Memory summary
free -h

# System uptime and load average
uptime

# Read CPU and memory directly from kernel
cat /proc/meminfo
cat /proc/cpuinfo | grep "model name" | head -1

Up next

Background jobs and job control in Bash

Sign in to track progress

How to monitor CPU and memory usage in Linux โ€” Process Management & System Monitoring โ€” Linux & Bash for Developers โ€” Script Valley โ€” Script Valley