Monitor CPU and memory usage, list running processes, and terminate unresponsive programs. Invoke when user asks "what processes are running", "kill process X", "CPU usage", "memory hogs", or "which process is using port 8080". Linux: ps/kill/pkill. Windows: tasklist/taskkill.
Monitor and manage running processes.
| Task | Linux | Windows |
|---|---|---|
| List processes | ps aux | tasklist |
| Top memory | `ps aux --sort=-%mem | head` |
| Kill by name | pkill name | taskkill /IM name.exe /F |
| Kill by PID | kill PID | taskkill /PID 1234 /F |
| Port to process | lsof -i :8080 | netstat -ano | findstr :8080 |
ps aux | head -20 # first 20 processes
ps aux --sort=-%cpu # sort by CPU
ps aux --sort=-%mem # sort by memory
tasklist
tasklist /FO TABLE # table format (default)
tasklist /FO CSV # CSV for parsing
tasklist /FI "STATUS eq running" # running only
tasklist /FI "MEMUSAGE gt 100000" # > 100MB
top -bn1 | head -20 # snapshot of top processes
ps aux | awk '{print $4"\t"$11}' | sort -rn | head # memory %
free -h # total system memory
df -h # disk space
tasklist /FI "MEMUSAGE gt 100000" /FO CSV | Sort-Object { [double]$_ -split ','[1] } | Select-Object -First 10
wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Value # memory
wmic diskdrive get model,size # disk space
Always try SIGTERM (15) first, then SIGKILL (9) as a last resort.
kill 12345 # SIGTERM (15) — graceful
kill -15 12345 # explicit SIGTERM
kill -9 12345 # SIGKILL — immediate, no cleanup
pkill firefox # SIGTERM by name
pkill -9 chrome # SIGKILL by name
killall process-name
taskkill /IM notepad.exe /F # by name
taskkill /PID 1234 /F # by PID
taskkill /IM chrome.exe /T /F # /T kills child processes too
# What's using port 8080?
lsof -i :8080
# or
ss -tlnp | grep :8080
netstat -ano | findstr :8080
# Then: tasklist /FI "PID eq 12345"
ps aux | grep -w Z # Z = zombie
Zombies have no resources but indicate a parent that didn't reap. Kill the parent:
kill -9 PARENT_PID
Child processes whose parent died. Re-parent to init (PID 1):
kill -17 -1 # sends SIGHUP to reparent
Lower nice = higher priority:
nice -n 10 command # start low priority
renice 5 -p PID # change running process priority
systemctl status nginx
systemctl restart nginx
systemctl stop nginx
systemctl list-units --type=service --state=running
Get-Service nginx # status
Start-Service nginx
Stop-Service nginx
Restart-Service nginx
tmux SkillTo schedule process monitoring:
crontab -e
# */5 * * * * ps aux --sort=-%cpu | head -5 >> /tmp/cpu_report.txt