commands

top — sample task statistics

Batch mode produces a finite snapshot. -p limits task rows to selected PIDs; summary may still reflect system statistics. Values depend on sampling and configuration. Use a fresh private workspace, ordinary user and bounded child processes; no sudo.

Formal Syntax & Structure

linux syntaxlinux
top -b -n COUNT -p PID

Parameters & Attributes

NameTypeDescription
-boptionBatch mode, without interactive commands.
-noptionTakes the maximum iteration count; use 1 for a single snapshot.
-poptionTakes the PID list to monitor.
COUNToperandPositive iteration limit, 1 for this example.
PIDoperandAuthorized process ID or comma-separated PID list.

Return Value

exit status and output

Batch mode produces a finite snapshot. -p limits task rows to selected PIDs; summary may still reflect system statistics. Values depend on sampling and configuration.

Working Example

Example Snippetlinux
top -b -n 1 -p "$$" > sample.txtgrep -E 'PID.*COMMAND' sample.txt >/dev/null && printf 'sample captured\n'
Linux Reference