Challenge - 5 Problems
Process Control Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Bash script controlling process execution?
Consider this Bash script that uses process control to manage execution order. What will it print?
Bash Scripting
echo "Start" (sleep 1 && echo "Middle") & echo "End" wait
Attempts:
2 left
💡 Hint
Remember that commands in parentheses run in the background and 'wait' pauses until they finish.
✗ Incorrect
The script prints 'Start' immediately, then starts a background process that sleeps 1 second before printing 'Middle'. Meanwhile, it prints 'End' immediately after 'Start'. The 'wait' command pauses the script until the background process finishes, so 'Middle' appears last.
🧠 Conceptual
intermediate1:30remaining
Why use 'wait' in Bash scripts with background processes?
Why is the 'wait' command important when managing background processes in Bash?
Attempts:
2 left
💡 Hint
Think about what happens if you don't wait for background jobs.
✗ Incorrect
Without 'wait', the script may finish before background jobs complete, causing unexpected behavior. 'wait' ensures the script pauses until those jobs are done.
📝 Syntax
advanced1:30remaining
Which Bash command correctly runs a process in the background and waits for it?
Select the option that correctly runs 'my_script.sh' in the background and waits for it to finish.
Attempts:
2 left
💡 Hint
The background operator '&' runs the command in the background; 'wait' should come after.
✗ Incorrect
Option A runs the script in the background and then waits for it to finish. Other options misuse 'wait' or background operators causing syntax errors or wrong behavior.
🔧 Debug
advanced1:30remaining
Identify the error in this Bash process control snippet
What error will this script produce and why?
Code:
sleep 5 &
wait 1234
Bash Scripting
sleep 5 & wait 1234
Attempts:
2 left
💡 Hint
Check if the PID given to wait belongs to a child process.
✗ Incorrect
The 'wait' command only waits for child processes of the current shell. If PID 1234 is not a child, it raises an error.
🚀 Application
expert2:30remaining
How to run multiple background jobs and wait for all to finish in Bash?
You want to run three scripts in parallel and wait until all finish before continuing. Which script snippet achieves this?
Attempts:
2 left
💡 Hint
Start all scripts in background, then use a single wait to pause until all finish.
✗ Incorrect
Option C runs all scripts in background and then waits for all to finish. Option C misuses wait, C waits after each script which is sequential, and D runs scripts sequentially without background.