Skip to content
shellmap

Find processes using the most CPU

List the top CPU-consuming processes — useful for performance triage, runaway-script detection, and capacity planning.

How to find processes using the most cpu in each shell

Bashunix
ps aux --sort=-%cpu | head -10
Zshunix
ps aux --sort=-%cpu | head -10
Fishunix
ps aux --sort=-%cpu | head -10
PowerShellwindows
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
cmd.exewindows
powershell -NoProfile -Command "Get-Process | Sort-Object CPU -Descending | Select-Object -First 10"

`wmic process` was the cmd-native answer but is DEPRECATED on Windows 11 24H2+ (removed from default install). Shell out to PowerShell — present on every Windows install since 7.

Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.

Gotchas & notes

  • GNU `ps --sort=-%cpu` (leading `-` is descending) is Linux-only. BSD/macOS `ps` has no `--sort` flag → use `ps -A -o pid,pcpu,comm | sort -k2 -nr | head -10`. Live-refreshing view: `top -bn1 -o %CPU` (Linux batch mode — single snapshot suitable for piping) vs `top -l 1 -o cpu` (macOS BSD — different flag name `-l` for "logging" and different sort key `cpu`).
  • pwsh `(Get-Process).CPU` returns CUMULATIVE PROCESSOR-SECONDS since the process started, NOT instantaneous %. A 30-day-old web server may show CPU=86400 while idle right now. For real-time per-process %: `(Get-Counter '\Process(*)\% Processor Time').CounterSamples | Sort-Object CookedValue -Descending` — Windows perf counters report 0–100 PER CORE (an 8-thread process pinned to all cores shows 800%). Divide by `(Get-CimInstance Win32_Processor).NumberOfLogicalProcessors` for a normalized 0–100 reading.
  • `htop` and `btop` are interactive replacements with colour, signals menus, and per-thread views, but they are NOT in base Linux/macOS — `apt install htop` / `brew install htop`. For ad-hoc scripting prefer `ps`/`top` (always present). `top -c` shows the FULL command line (helps distinguish 12 `python` processes); `top -p $PID` filters to one process. macOS `top` defaults to ordering by PID — always pass `-o cpu`.
  • For time-series CPU (not just a snapshot): `pidstat 1 5` (sysstat — `apt install sysstat`) prints 5 one-second samples per PID, ideal for catching spikes that a single `ps` misses. `dstat -tcp --top-cpu` shows system + per-process. pwsh: `1..5 | %% { Get-Counter '\Process(*)\% Processor Time' -SampleInterval 1 }`. Production: ship to Prometheus `process_exporter` + Grafana; one-off `ps`/`top` lies under bursty workloads.

Related commands

Related tasks