commands

wait — collect child status

Wait for the specified child known to the shell; returns its status. An unrelated process is not a waitable child. Capture $! immediately after launching. Use a fresh private workspace, ordinary user and bounded child processes; no sudo.

Formal Syntax & Structure

linux syntaxlinux
wait PID

Parameters & Attributes

NameTypeDescription
PIDoperandknown child PID

Return Value

exit status and output

Wait for the specified child known to the shell; returns its status. An unrelated process is not a waitable child. Capture $! immediately after launching.

Working Example

Example Snippetlinux
bash -c 'exit 7' &child=$!if wait "$child"; then printf 'ok\n'; else printf 'status=%s\n' "$?"; fi
Linux Reference