Skip to content
Latchkey

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 -20

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →