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 PIDParameters & Attributes
| Name | Type | Description |
|---|---|---|
| -b | option | Batch mode, without interactive commands. |
| -n | option | Takes the maximum iteration count; use 1 for a single snapshot. |
| -p | option | Takes the PID list to monitor. |
| COUNT | operand | Positive iteration limit, 1 for this example. |
| PID | operand | Authorized 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'