0
0
Linux CLIscripting~10 mins

jobs command in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - jobs command
Start shell session
Run command in background (&)
jobs command typed
Shell lists background jobs
User sees job IDs, status, and commands
User can manage jobs (fg, bg, kill)
The jobs command shows all background jobs in the current shell session with their status and job IDs.
Execution Sample
Linux CLI
sleep 30 &
jobs
Run a sleep command in the background and then list all background jobs.
Execution Table
StepCommand EnteredShell ActionOutput
1sleep 30 &Starts sleep in background, assigns job ID[1] 12345
2jobsLists all background jobs[1]+ Running sleep 30
💡 No more commands; jobs output shows current background jobs.
Variable Tracker
VariableStartAfter 1After 2Final
jobs_listempty[1] sleep 30[1] sleep 30[1] sleep 30
Key Moments - 3 Insights
Why does the jobs command only show background jobs and not all running processes?
Because jobs only tracks processes started in the current shell session with & or stopped jobs, as shown in the execution_table step 2 output.
What does the number in brackets like [1] mean in the jobs output?
It is the job ID assigned by the shell to manage the background job, visible in execution_table step 1 output.
Why might a job show as 'Stopped' instead of 'Running' in jobs output?
Because the job was paused (e.g., with Ctrl+Z), so jobs shows its status as 'Stopped' as per the output format in step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the job ID assigned to the sleep command?
A[12345]
B[30]
C[1]
D[&]
💡 Hint
Check the output column in step 1 of the execution_table where the job ID is shown in brackets.
At which step does the shell list the background jobs?
AStep 2
BAfter exit
CStep 1
DBefore any command
💡 Hint
Look at the Command Entered column to see when 'jobs' command is typed.
If the sleep command was run without &, what would the jobs command show?
AIt would show the sleep job as running
BIt would show no jobs
CIt would show an error
DIt would list all system processes
💡 Hint
Recall that jobs only lists background jobs started with & as shown in the key_moments.
Concept Snapshot
jobs command:
- Lists background jobs in current shell
- Shows job ID, status, and command
- Only tracks jobs started with & or stopped jobs
- Use fg/bg to manage jobs
- Useful to monitor and control background tasks
Full Transcript
The jobs command in Linux shows all background jobs running in the current shell session. When you run a command with & at the end, it starts in the background and gets a job ID like [1]. Typing jobs lists these jobs with their status such as Running or Stopped. This helps you keep track of tasks running behind the scenes. Jobs only shows processes started in the current shell with & or those stopped with Ctrl+Z. You can bring jobs to the foreground with fg or continue them in background with bg. This visual trace showed running 'sleep 30 &' which started a background job with ID [1], then running jobs listed it as running. Understanding jobs helps manage multiple tasks easily in the shell.