wait — Pause until background jobs or processes finish across all 5 shells
Equivalents in every shell
waitBuiltin. `wait` (no args) blocks until ALL background jobs in the current shell exit; `wait %1` waits for job number 1; `wait $PID` waits for a specific PID. Exit status echoes the awaited process.
waitSame as bash. `wait %job-spec` and `wait $PID` both work. Bare `wait` collects every backgrounded job started in the current shell.
waitBuiltin since fish 3.0. Same `wait %1` / `wait $PID` syntax. Fish does NOT auto-reap finished jobs into `$status` — you must call `wait` to collect their exit codes.
Wait-Process -Name notepadWaits for an EXTERNAL process by name or PID. For PowerShell background jobs (`Start-Job`, `Start-ThreadJob`) use `Wait-Job` instead. `Wait-Process -Timeout 30` throws when the timer expires without killing the target.
start /wait program.exe`start /wait` is the only cmd primitive for waiting on a child process to finish before the next line runs. There is no equivalent of `wait $PID` — you launch and wait in one operation, with no way to wait for a PID launched elsewhere.
Worked examples
Wait for every background job to complete
long_job & long_job & waitlong_job & long_job & waitlong_job & long_job & waitGet-Job | Wait-JobWait for a specific PID and capture its exit status
long_job & PID=$!; wait $PID; echo "exit=$?"long_job & PID=$!; wait $PID; echo "exit=$?"$p = Start-Process notepad -PassThru; $p.WaitForExit(); $p.ExitCodeWait with a hard timeout
long_job & PID=$!; (sleep 30; kill $PID 2>/dev/null) & wait $PIDWait-Process -Id $PID -Timeout 30; if (Get-Process -Id $PID -ErrorAction SilentlyContinue) { Stop-Process -Id $PID }Gotchas
- Bash `wait` exit status is the EXIT CODE of the LAST awaited job, not an aggregate. Five jobs in parallel where three fail still reports only one of those failures — to detect any failure, `wait` on each PID individually and OR the statuses.
- Bare `wait` with no args BLOCKS until every background job exits — including ones already collected. Use `wait $PID1 $PID2 ...` explicitly to wait on only the targets you care about, especially in long-running scripts.
- A PID that is NOT a child of the current shell cannot be waited on. `wait 12345` for a PID started in a different terminal returns immediately with exit status 127 (`not a child`), not actually waiting — a frequent surprise when reusing PID files.
- PowerShell `Wait-Process -Timeout 30` does NOT kill the process when the timer expires — it just throws a non-terminating error. Follow up with `Stop-Process -Id $PID` to actually enforce the timeout.
- Cmd `start /wait` runs the child in a NEW console window by default. Use `start /b /wait` to keep it in the current console; `/b` also blocks Ctrl-C forwarding, which can break interactive children that expect to receive the signal.
WSL & PowerShell Core notes
Common tasks using wait
- Run a command with a timeout
Kill a command if it has not finished within N seconds — the standard hedge against hung network calls, runaway scripts, and tests that should never block forever.
- Run multiple commands in parallel
Execute several commands concurrently and wait for them all — useful for batch downloads, fan-out tasks, and CI test sharding.
- Wait for a process to finish
Block until a given process exits — useful for sequencing, dependency-management scripts, and orchestrated shutdowns.