wait कमांड
wait finish line पर खड़े रहकर आपके उन friends का इंतज़ार करने जैसा है जो background में भाग गए थे। Script रुक जाता है जब तक वे सभी वापस न आ जाएं।
In this page:
Syntax
command &
wait [process_id]
wait
wait एक script को रोकता है जब तक एक background job खत्म न हो, या अगर बिना किसी argument के call किया जाए तो जब तक सभी background jobs खत्म न हों। wait $pid एक specific job के लिए wait करता है और इसका exit status capture करता है।
मल्टिपल background tasks को आगे बढ़ने से पहले coordinate करने के लिए यह essential है।
Note:
wait को बिना किसी argument के call करें तब तक रुकने के लिए जब तक script ने start किए हर *एक* background job complete न हो जाए।उदाहरण: wait
#!/bin/bash
sleep 1 &
sleep 1 &
echo "Waiting for all background jobs..."
wait
echo "All background jobs finished"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
waitको बिना PID के call करना और एक specific job का exit status expect करना।- Command पर
&भूल जाना, इसलिए wait करने के लिए कुछ नहीं है। - उस PID के लिए wait करना जो current shell का child नहीं है।
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: