0
0
Bash Scriptingscripting~10 mins

Why process control manages execution in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run a command in the background.

Bash Scripting
sleep 10 [1]
Drag options to blanks, or click blank then click option'
A&
B&&
C|
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' runs the next command only if the first succeeds, not backgrounding.
Using '|' pipes output, not backgrounding.
Using ';' runs commands sequentially, not backgrounding.
2fill in blank
medium

Complete the code to wait for a background process to finish.

Bash Scripting
sleep 5 &
[1]
Drag options to blanks, or click blank then click option'
Akill
Bwait
Cexit
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stop' does not wait for processes.
Using 'kill' terminates processes instead of waiting.
Using 'exit' ends the script immediately.
3fill in blank
hard

Fix the error in the code to correctly bring a background job to the foreground.

Bash Scripting
sleep 20 &
[1]
Drag options to blanks, or click blank then click option'
Ajobs 1
Bbg 1
Cfg 1
Dkill 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bg' keeps the job in the background.
Using 'jobs' lists jobs but does not bring them forward.
Using 'kill' terminates the job.
4fill in blank
hard

Fill both blanks to create a loop that runs a command and waits for it to finish before continuing.

Bash Scripting
for i in {1..3}; do
  sleep 2 [1]
  [2]
  echo "Done $i"
done
Drag options to blanks, or click blank then click option'
A&
Bwait
Cfg
Dkill
Attempts:
3 left
💡 Hint
Common Mistakes
Not using '&' causes the loop to wait naturally, no need for wait.
Using 'fg' does not wait but brings jobs to foreground.
Using 'kill' stops the process.
5fill in blank
hard

Fill all three blanks to create a dictionary-like output of job IDs and their statuses.

Bash Scripting
jobs_output=$(jobs)
while read -r line; do
  job_id=$(echo $line | awk [1])
  status=$(echo $line | awk [2])
  echo "Job $[3]: $status"
done <<< "$jobs_output"
Drag options to blanks, or click blank then click option'
A'{print $1}'
B'{print $2}'
Cjob_id
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field numbers in awk.
Using variable names incorrectly in echo.
Not reading the jobs output line properly.