0
0
Linux CLIscripting~10 mins

Background processes (&) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Background processes (&)
User types command with &
Shell starts command
Command runs in background
Shell prompt returns immediately
User can run other commands
Background command finishes
Shell shows job completion message
The shell runs the command in the background, freeing the prompt immediately for new commands while the background job runs.
Execution Sample
Linux CLI
sleep 5 &
echo "Done"
Runs 'sleep 5' in the background and immediately prints 'Done' without waiting.
Execution Table
StepActionShell BehaviorOutputPrompt State
1User types 'sleep 5 &'Shell recognizes & for backgroundPrompt waits for input
2Shell starts 'sleep 5' in backgroundCommand runs without blockingPrompt returns immediately
3User types 'echo "Done"'Shell executes echo immediatelyDonePrompt returns immediately
4'sleep 5' finishes after 5 secondsShell prints job completion message[1]+ Done sleep 5Prompt ready for input
💡 Background job finishes and shell shows completion message; prompt stays ready for new commands.
Variable Tracker
VariableStartAfter Step 2After Step 4
sleep_processnot runningrunning in backgroundfinished
Key Moments - 3 Insights
Why does the shell prompt return immediately after typing a command with &?
Because the & tells the shell to run the command in the background, so it does not wait for the command to finish before showing the prompt again, as seen in execution_table step 2.
What happens if you run a command without &?
The shell waits for the command to finish before returning the prompt. With &, the shell does not wait, shown by the immediate prompt return in step 2.
How does the shell notify you when a background job finishes?
It prints a job completion message like '[1]+ Done sleep 5' after the background process ends, as shown in execution_table step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the shell prompt state immediately after starting 'sleep 5 &'?
APrompt waits until 'sleep 5' finishes
BPrompt disappears
CPrompt returns immediately ready for input
DPrompt shows an error
💡 Hint
Check execution_table row 2 under 'Prompt State'
At which step does the shell print the job completion message?
AStep 4
BStep 2
CStep 3
DStep 1
💡 Hint
Look at the 'Output' column in execution_table for job completion
If you remove the & from 'sleep 5 &', how would the prompt behave?
APrompt returns immediately
BPrompt waits until 'sleep 5' finishes
CPrompt shows an error
DPrompt runs two commands at once
💡 Hint
Refer to key_moments about shell waiting behavior without &
Concept Snapshot
Background processes (&) in Linux shell:
- Add & at command end to run it in background
- Shell prompt returns immediately, no waiting
- Background job runs independently
- Shell shows job done message when finished
- Useful to keep working while long tasks run
Full Transcript
When you add an ampersand (&) at the end of a command in the Linux shell, the shell runs that command in the background. This means the shell does not wait for the command to finish and immediately shows you the prompt so you can type other commands. For example, running 'sleep 5 &' starts a 5-second pause in the background. Right after, you can run 'echo "Done"' and see the output immediately. After 5 seconds, the shell will notify you that the background job finished. This helps you keep working without waiting for long commands to complete.