commands
ps — process snapshot
Select a process by PID and report requested columns. STAT starts with a state letter; output is a momentary observation. Avoid treating names or PIDs as durable identity. Use a fresh private workspace, ordinary user and bounded child processes; no sudo.
Formal Syntax & Structure
linux syntaxlinux
ps -p PID -o FORMATParameters & Attributes
| Name | Type | Description |
|---|---|---|
| -p | option | PID selection |
| -o | option | output fields |
| PID | operand | Process ID or comma-separated PID list for -p. |
| FORMAT | operand | Output column list for -o; e.g. comm= suppresses that column heading. |
Return Value
exit status and output
Select a process by PID and report requested columns. STAT starts with a state letter; output is a momentary observation. Avoid treating names or PIDs as durable identity.
Working Example
Example Snippetlinux
name=$(ps -p "$$" -o comm=) || exit 1test -n "$name" || exit 1printf "%s\n" "$name"