0
0
Linux CLIscripting~20 mins

fg and bg commands in Linux CLI - Practice Problems & Coding Challenges

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

sleep 30 &
jobs
fg %1


What will the jobs command output before fg %1 is run?
Linux CLI
sleep 30 &
jobs
fg %1
A[1]+ Done sleep 30
B[1]+ Stopped sleep 30
C[1]- Running sleep 30 &
D[1]+ Running sleep 30 &
Attempts:
2 left
💡 Hint
Think about what happens when a command is run in the background with & and how jobs lists them.
💻 Command Output
intermediate
2:00remaining
What happens after running bg on a stopped job?
You start a command and stop it with Ctrl+Z. Then you run bg %1. What will be the job status if you run jobs immediately after?
Linux CLI
sleep 30
# Press Ctrl+Z to stop
bg %1
jobs
A[1]+ Stopped sleep 30
B[1]+ Running sleep 30 &
C[1]+ Done sleep 30
D[1]+ Terminated sleep 30
Attempts:
2 left
💡 Hint
bg resumes a stopped job in the background.
📝 Syntax
advanced
2:00remaining
Which command correctly brings job 2 to the foreground?
You have multiple jobs running. Which of these commands correctly brings job number 2 to the foreground?
Afg %2
Bfg job2
Cfg 2
Dfg #2
Attempts:
2 left
💡 Hint
Jobs are referenced by a percent sign followed by the job number.
🔧 Debug
advanced
2:00remaining
Why does this bg command fail with 'no such job' error?
You run:
sleep 100 &
bg %1


But get the error: 'bg: no such job'. Why?
Linux CLI
sleep 100 &
bg %1
ABecause the percent sign is missing in the command.
BBecause the job number 1 does not exist yet.
CBecause bg requires the job to be stopped, not running.
DBecause the job is already running in the background, bg cannot resume it.
Attempts:
2 left
💡 Hint
bg only works on stopped jobs.
🚀 Application
expert
2:00remaining
How to bring the most recent stopped job to foreground using a single command?
You have multiple jobs stopped and running. Which command brings the most recent stopped job to the foreground?
Afg %+
Bfg %%
Cfg %-
Dfg %1
Attempts:
2 left
💡 Hint
The %+ symbol refers to the current job.