Resource usage

2 snippets across 2 stacks - Bash & Linux, Docker

SHBash & Linux

Interactive Process Viewer

SH · Process Management
Syntax
top
htop
Example
top -o %MEM
htop -u deploy

Note top is always available. In top: press M to sort by memory, P by CPU, k to kill a process, q to quit. htop is a friendlier alternative with mouse support, color, and tree view but may need installing. -u filters by user.

DKDocker

Live Resource Usage

DK · Containers
Syntax
docker stats [container...]
Example
docker stats
docker stats web-api db-postgres --no-stream
Output
CONTAINER   CPU %   MEM USAGE / LIMIT     NET I/O         BLOCK I/O
web-api     0.50%   85.2MiB / 512MiB      1.2kB / 648B    0B / 4.1kB

Note Without arguments, it shows all running containers. Add --no-stream to get a single snapshot instead of a live-updating display.

Frequently asked questions

How does Bash & Linux handle resource usage?
This task is covered in 2 stacks on this page: Bash & Linux, Docker. The "Interactive Process Viewer" snippet in Bash & Linux uses `top`.
Which command does the Bash & Linux example use?
The "Interactive Process Viewer" snippet uses `top`, from the Process Management section of the Bash & Linux cheat sheet.
Which stacks cover "resource usage" on this page?
Bash & Linux, Docker. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Interactive Process Viewer": top is always available. In top: press M to sort by memory, P by CPU, k to kill a process, q to quit. htop is a friendlier alternative with mouse support, color, and tree view but may need installing. -u filters by user.