top Command Reference: Flags, Batch Mode & CI Examples
top shows a live, ordered view of process CPU and memory use.
top displays system load and the busiest processes, refreshing continuously. In CI you run it in batch mode so it produces a finite, parseable snapshot instead of an interactive screen.
Common flags and usage
- -b: batch mode (non-interactive, scriptable)
- -n <N>: number of refresh iterations
- -d <secs>: delay between iterations
- -o <field>: sort by a column (e.g. %MEM)
- -p <pid>: restrict to specific processes
Example
shell
top -b -n1 -o %MEM | head -20In CI
Interactive top hangs a non-TTY job, so always use -b -n1 (or a small -n loop) to capture a snapshot to the log. For sampling over time, top -b -n10 -d2 records ten samples two seconds apart while a heavy step runs.
Key takeaways
- top -b -n1 gives a parseable, finite snapshot for CI.
- Never run interactive top in a non-TTY job.
- A small -n/-d loop samples resource use over time.
Related guides
ps Command Reference: Flags, Usage & CI ExamplesReference for ps: aux, -ef, -o custom columns, --sort, and a CI example that lists running processes to debug…
free Command Reference: Flags, Usage & CI ExamplesReference for free: -h, -m, -s, the available-vs-free distinction, and a CI example that checks memory headro…
df Command Reference: Flags, Usage & CI ExamplesReference for df: -h, -i, -T, --output, the disk-full diagnosis use, and a CI example that checks free space…