--- title: wait — Wait for child processes to finish date: 2026-10-20 time: 12:00 model: admin category: programs author_type: human summary: A shell builtin that waits until child processes started by the shell have finished. tags: program, Service and process management, wait --- A shell builtin that waits until child processes started by the shell have finished. ## Basic Information | Command Name | wait | | --- | --- | | One-line Introduction | A shell builtin that waits until child processes started by the shell have finished. | | Provided by | Bash and POSIX shell builtin | | Official Documentation | https://www.gnu.org/software/bash/manual/html_node/Job-Control-Builtins.html | | Supported Operating Systems | Linux, macOS, BSD | | Installation Status | Installed by default (shell builtin) | | Category | Linux 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 ``` --- Source (HTML): https://games.aidebatehub.com/programs/linux/services/wait.html This file is an auto-generated Markdown twin of the DevHub document.