0
0
Linux CLIscripting~20 mins

Background processes (&) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Background Process Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command sequence?
Consider the following commands run in a Linux shell:

sleep 2 & echo Done

What will be printed immediately after running these commands?
Linux CLI
sleep 2 & echo Done
ADone after 2 seconds
BDone
CNo output until sleep finishes
Dsleep: command not found
Attempts:
2 left
💡 Hint
The ampersand (&) runs the first command in the background, so the shell does not wait for it.
💻 Command Output
intermediate
2:00remaining
What happens when you run multiple background jobs?
You run these commands in a Linux shell:

sleep 3 & sleep 1 & sleep 2 & wait

What will happen after running these commands?
Linux CLI
sleep 3 & sleep 1 & sleep 2 & wait
AThe shell waits until all three sleep commands finish before returning to prompt
BThe shell returns immediately without waiting
COnly the first sleep command runs in background, others run in foreground
DThe shell waits only for the first sleep command
Attempts:
2 left
💡 Hint
The 'wait' command waits for all background jobs to finish.
🔧 Debug
advanced
1:30remaining
Why does this background command fail to run properly?
You try to run this command in a shell:

echo Hello & & echo World

What error will the shell produce?
Linux CLI
echo Hello & & echo World
Abash: syntax error near unexpected token `&'
BHello\nWorld
CNo output, command hangs
DHello
Attempts:
2 left
💡 Hint
Check how many ampersands are used and their placement.
🚀 Application
advanced
2:00remaining
How to run a script in background and save its output to a file?
You want to run a script named backup.sh in the background and save both its output and errors to backup.log. Which command does this correctly?
A./backup.sh >& backup.log &
B./backup.sh & > backup.log 2>&1
C./backup.sh &> backup.log 2>&1
D./backup.sh > backup.log 2>&1 &
Attempts:
2 left
💡 Hint
Redirect output before putting command in background.
🧠 Conceptual
expert
2:00remaining
What is the effect of running a command with nohup and & together?
You run this command:

nohup longtask.sh &

What happens to the process if you close the terminal?
AThe process stops immediately when terminal closes
BThe process pauses until terminal is reopened
CThe process keeps running even after terminal closes
DThe process restarts automatically after terminal closes
Attempts:
2 left
💡 Hint
nohup prevents hangup signals from stopping the process.