Bird
Raised Fist0
Linux CLIscripting~20 mins

jobs command in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Jobs Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of jobs command with background processes
You run these commands in a Linux shell:
sleep 30 &
sleep 40 &
jobs

What is the expected output of the jobs command?
A
[1]-  Running                 sleep 30 &
[2]+  Running                 sleep 40 &
BNo output, jobs command shows nothing
C
[1]+  Done                    sleep 30 &
[2]-  Done                    sleep 40 &
D
[1]+  Running                 sleep 30 &
[2]-  Running                 sleep 40 &
Attempts:
2 left
💡 Hint
Jobs are numbered in order started; the last job is marked with a plus (+).
💻 Command Output
intermediate
2:00remaining
Effect of fg command on jobs
You start a background job:
sleep 60 &

Then run jobs and see:
[1]+  Running                 sleep 60 &

What happens when you run fg %1?
ASyntax error: fg requires a job name, not a number
BThe sleep 60 job is terminated immediately
CNothing happens, job stays in background
DThe sleep 60 job moves to foreground and blocks the shell until it finishes
Attempts:
2 left
💡 Hint
The fg command brings a background job to foreground.
🔧 Debug
advanced
2:00remaining
Why does jobs show no output?
You run this sequence:
sleep 20 &
jobs

But jobs shows no output. What is the most likely reason?
AThe jobs command requires root privileges
BThe sleep command finished before jobs was run
CThe shell session is not interactive, so jobs command shows nothing
DThe sleep command was run in foreground, so no jobs exist
Attempts:
2 left
💡 Hint
Jobs only work in interactive shells.
🧠 Conceptual
advanced
2:00remaining
Understanding job control signals
You have a job running in foreground. You press Ctrl+Z. What happens to the job and how does jobs reflect this?
AThe job continues running in background, jobs shows 'Running'
BThe job is suspended (stopped), and jobs shows it as 'Stopped'
CThe job is terminated, and jobs shows no entry
DThe job is paused but jobs shows 'Done'
Attempts:
2 left
💡 Hint
Ctrl+Z sends SIGTSTP to suspend the job.
🚀 Application
expert
3:00remaining
Counting background jobs with jobs command
You run multiple background jobs:
sleep 10 &
sleep 20 &
sleep 30 &

Write a one-liner command using jobs and other shell tools to count how many background jobs are currently running.
Ajobs | grep Running | wc -l
Bjobs -p | wc -l
Cjobs | wc -l
Dps aux | grep sleep | wc -l
Attempts:
2 left
💡 Hint
Filter jobs output for Running status, then count lines.

Practice

(1/5)
1. What does the jobs command do in a Linux shell?
easy
A. Lists background and stopped tasks in the current shell
B. Shows all running processes on the system
C. Terminates all background jobs
D. Starts a new background job

Solution

  1. Step 1: Understand the purpose of jobs

    The jobs command shows tasks started in the current shell that are either stopped or running in the background.
  2. Step 2: Compare with other options

    Options A, B, and C describe different commands or actions unrelated to jobs.
  3. Final Answer:

    Lists background and stopped tasks in the current shell -> Option A
  4. Quick Check:

    jobs lists current shell jobs [OK]
Hint: Remember: jobs shows your shell's paused or background tasks [OK]
Common Mistakes:
  • Confusing jobs with ps command
  • Thinking jobs starts or kills tasks
  • Assuming jobs shows system-wide processes
2. Which of the following is the correct syntax to list all jobs with their process IDs using the jobs command?
easy
A. jobs -a
B. jobs --list-pid
C. jobs -p
D. jobs -l

Solution

  1. Step 1: Recall jobs options

    The -l option with jobs lists jobs with their process IDs.
  2. Step 2: Verify other options

    -p lists only PIDs without job info, --list-pid is invalid, and -a shows all jobs including those not started by the shell.
  3. Final Answer:

    jobs -l -> Option D
  4. Quick Check:

    jobs -l shows jobs with PIDs [OK]
Hint: Use -l to see job numbers plus process IDs [OK]
Common Mistakes:
  • Using invalid options like --list-pid
  • Confusing -p with -l
  • Assuming -a shows PIDs
3. Given the following shell session:
$ sleep 100 &
[1] 12345
$ sleep 200 &
[2] 12346
$ jobs
[1]+  Running                 sleep 100 &
[2]-  Running                 sleep 200 &
What will be the output of jobs -l?
medium
A. [1]+ 12345 Stopped sleep 100 & [2]- 12346 Stopped sleep 200 &
B. [1]+ Running sleep 100 & [2]- Running sleep 200 &
C. [1]+ 12345 Running sleep 100 & [2]- 12346 Running sleep 200 &
D. No jobs to display

Solution

  1. Step 1: Understand jobs output

    The jobs command shows job number, status, and command. The -l option adds the process ID after the job number.
  2. Step 2: Match output format

    Since both jobs are running with PIDs 12345 and 12346, jobs -l will show job number, PID, status, and command.
  3. Final Answer:

    [1]+ 12345 Running sleep 100 & [2]- 12346 Running sleep 200 & -> Option C
  4. Quick Check:

    jobs -l adds PIDs to normal jobs output [OK]
Hint: jobs -l shows PIDs next to job numbers [OK]
Common Mistakes:
  • Ignoring PIDs in output
  • Confusing Running with Stopped status
  • Expecting no jobs listed
4. You ran sleep 300 & and then jobs shows the job as stopped. Which command will resume the job in the background?
medium
A. kill %1
B. bg %1
C. fg %1
D. stop %1

Solution

  1. Step 1: Understand job states and commands

    A stopped job is paused. The bg command resumes it in the background, while fg resumes it in the foreground.
  2. Step 2: Choose correct command for background resume

    Since the question asks to resume in background, bg %1 is correct. kill terminates, and stop is invalid here.
  3. Final Answer:

    bg %1 -> Option B
  4. Quick Check:

    Resume stopped job in background = bg %job_number [OK]
Hint: Use bg %job_number to resume stopped jobs in background [OK]
Common Mistakes:
  • Using fg instead of bg for background resume
  • Trying to kill instead of resume
  • Using invalid stop command
5. You have multiple background jobs running. You want to bring job number 3 to the foreground and then stop it temporarily. Which sequence of commands should you use?
hard
A. fg %3, then press Ctrl+Z
B. bg %3, then press Ctrl+C
C. kill %3, then fg %3
D. jobs %3, then stop %3

Solution

  1. Step 1: Bring job 3 to foreground

    Use fg %3 to bring job number 3 to the foreground so you can interact with it.
  2. Step 2: Stop the job temporarily

    Pressing Ctrl+Z sends a stop signal, pausing the job and returning control to the shell.
  3. Final Answer:

    fg %3, then press Ctrl+Z -> Option A
  4. Quick Check:

    Foreground job then Ctrl+Z to stop it [OK]
Hint: Use fg %job then Ctrl+Z to pause foreground job [OK]
Common Mistakes:
  • Using bg instead of fg to bring job forward
  • Trying to kill instead of stop
  • Using invalid stop command
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard