Korean

wait — Wait for child processes to finish

Linux / Service and process management / wait.html

Service and process managementOriginalRegistered 2026-10-20T09:00:00+09:00

A shell builtin that waits until child processes started by the shell have finished.

Basic Information

Command Namewait
One-line IntroductionA shell builtin that waits until child processes started by the shell have finished.
Provided byBash and POSIX shell builtin
Official Documentationhttps://www.gnu.org/software/bash/manual/html_node/Job-Control-Builtins.html
Supported Operating SystemsLinux, macOS, BSD
Installation StatusInstalled by default (shell builtin)
CategoryLinux service and process management (tags: Process and resource management (tags: job control, synchronization, script))

What is this command?

wait pauses a script until background children finish.

With a PID or job number it waits for that target only and returns its exit status.

What problems does it solve?

  • Run the next step only after parallel jobs finish.
  • Check the exit code of a background job.
  • Ensure completion before cleaning temp files.
  • Fan out to several hosts and collect results.

Key features

Wait for all

Without arguments it waits for all children.

  • When to use: When waiting for all parallel jobs
  • What you get: Execution continues after all children end
  • Limitations: The status reflects the last target

Wait for a PID

A PID waits for that process only.

  • When to use: When one job must complete
  • What you get: That process exit status
  • Limitations: An unknown PID fails immediately

Collecting exit codes

Use $? to read the result after each wait.

  • When to use: When failures must be distinguished
  • What you get: Per-job success or failure
  • Limitations: Waiting on many keeps only the last status

Installation and usage

Check whether it is installed

help wait

man bash # wait is a shell builtin

Real-world examples

Wait for all

Wait until background jobs finish.

# Wait for every background job
wait

Wait for a PID

Wait for one PID.

# Wait for a specific child
bg_pid=$!
wait $bg_pid

Synchronize parallel jobs

Start several jobs and wait for all.

# Run three jobs in parallel, then wait
for h in web1 web2 web3; do ssh $h uptime & done
wait