Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to wait for all background processes to finish before continuing.
Bash Scripting
echo "Start"; sleep 2 & sleep 3 & [1]; echo "Done"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sleep' instead of 'wait' does not wait for background jobs.
Using 'kill' or 'exit' will stop the script or processes incorrectly.
✗ Incorrect
The 'wait' command pauses the script until all background jobs finish.
2fill in blank
mediumComplete the code to wait for a specific background process using its process ID.
Bash Scripting
sleep 5 & pid=$!; echo "Waiting for process"; [1] $pid; echo "Process done"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'kill' will terminate the process instead of waiting.
Using 'jobs' only lists jobs but does not wait.
✗ Incorrect
The 'wait' command can take a process ID to wait for that specific job.
3fill in blank
hardFix the error in the code to properly wait for all background jobs before printing "Finished".
Bash Scripting
sleep 4 & sleep 3 & sleep 2 & [1]; echo "Finished"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'wait $!' waits only for the last job, not all jobs.
Using 'sleep' or 'kill' does not wait properly.
✗ Incorrect
Using 'wait' without arguments waits for all background jobs, ensuring 'Finished' prints last.
4fill in blank
hardFill both blanks to create a loop that waits for each background job individually using their PIDs stored in an array.
Bash Scripting
pids=(); sleep 3 & pids+=($!); sleep 2 & pids+=($!); for pid in "${pids[@]}"; do [1] $pid; done; echo [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sleep' inside the loop does not wait for jobs.
Printing the wrong message or before waiting.
✗ Incorrect
The loop uses 'wait' on each PID to wait for each job, then prints a message after all finish.
5fill in blank
hardFill all three blanks to start three background jobs, wait for all, and then print a summary message.
Bash Scripting
sleep 1 & sleep 2 & sleep 3 & [1]; echo [2] [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sleep' instead of 'wait' does not wait for jobs.
Printing message before waiting.
✗ Incorrect
The 'wait' command pauses until all jobs finish, then the echo prints a clear message.