jobs Command in Linux: List and Manage Background Jobs

By 

•

Updated on

•

7 min read

Linux jobs command listing background processes

The jobs command is a Bash built-in that lists all background and suspended processes associated with the current shell session. It shows the job ID, state, and the command that started each job.

This article explains how to use the jobs command, what each option does, and how job specifications work for targeting individual jobs.

Syntax

The general syntax for the jobs command is:

txt
jobs [OPTIONS] [JOB_SPEC...]
jobs -x COMMAND [ARGS...]

When called without arguments, jobs lists all active jobs in the current shell.

Listing Jobs

To see all background and suspended jobs, run jobs without any arguments:

Terminal
jobs

If you suspend Vim with Ctrl+Z and then start ping in the background, the output will look similar to this:

output
[1]+  Stopped                    vim notes.txt
[2]-  Running                    ping google.com > /dev/null &

Each line shows:

  • The job number in brackets ([1], [2])
  • A + or - sign indicating the current and previous job (more on this below)
  • The job state (Running, Stopped, Done)
  • The command that started the job

The stopped Vim job is marked with + even though ping started later. Bash keeps a stopped job as the current job, so running fg without arguments brings Vim back to the foreground.

To include the process ID (PID) in the output, use the -l option:

Terminal
jobs -l
output
[1]+ 14205 Stopped                    vim notes.txt
[2]- 14230 Running                    ping google.com > /dev/null &

The PID is useful when you need to send a signal to a process with the kill command.

Job States

Jobs reported by the jobs command can be in one of these states:

  • Running - The process is actively executing in the background.
  • Stopped - The process has been suspended, typically by pressing Ctrl+Z. A job stopped by another signal shows as Stopped (signal).
  • Done - The process finished with exit status 0. This state appears once and is then cleared from the list.
  • Exit N - The process finished with a non-zero exit status, for example Exit 1.
  • Terminated - The process was killed by SIGTERM, the default signal sent by kill.
  • Killed - The process was killed by SIGKILL, for example with kill -9.

When a background job finishes, Bash normally reports its final status before displaying the next prompt.

Job Specifications

Job specifications (job specs) let you target a specific job when using commands like fg, bg, kill , or disown. They always start with a percent sign (%):

  • %1, %2, … - Refer to a job by its number.
  • %% or %+ - The current job, marked with +. This is usually the job you most recently started in the background or suspended. A stopped job stays current even after you start a newer background job.
  • %- - The previous job (marked with -).
  • %string - The job whose command starts with string. For example, %ping matches a job started with ping google.com.
  • %?string - The job whose command contains string anywhere. For example, %?google also matches ping google.com.

If a prefix or substring matches more than one job, Bash prints an ambiguous job spec error. Use the job number instead.

Here is a practical example. Start two background jobs:

Terminal
sleep 300 &
ping -c 100 google.com > /dev/null &

Now list them:

Terminal
jobs
output
[1]-  Running                    sleep 300 &
[2]+  Running                    ping -c 100 google.com > /dev/null &

You can bring the sleep job to the foreground by its number:

Terminal
fg %1

Or by the command prefix:

Terminal
fg %sleep

Both are equivalent and bring job [1] to the foreground.

Options

The jobs command accepts the following options:

  • -l - List jobs with their process IDs in addition to the normal output
  • -p - Print only the PID of each job’s process group leader (useful for scripting)
  • -r - List only running jobs
  • -s - List only stopped (suspended) jobs
  • -n - Show only jobs whose status has changed since the last notification
  • -x COMMAND - Run COMMAND after replacing each job spec in its arguments with the job’s process group ID

To show only running jobs:

Terminal
jobs -r

To get just the PIDs of all jobs:

Terminal
jobs -p
output
14205
14230

Using jobs in Scripts

Job control is off in a non-interactive script, but Bash still tracks the background processes the script starts. The jobs command lists them, and jobs -p prints their PIDs. What does not work is moving a job between the foreground and the background. Calling fg or bg in a script fails with a fg: no job control error. To turn job control on in a script, add set -m near the top.

To track a specific task, save its process ID from $! right after you start it:

sh
# Start a background task
long_task &
task_pid=$!

# Poll until it finishes
while kill -0 "$task_pid" 2>/dev/null; do
  echo "Task is still running..."
  sleep 5
done

echo "Task complete."

To wait for several background tasks, store their PIDs and pass them to wait:

sh
task_a &
pid_a=$!

task_b &
pid_b=$!

task_c &
pid_c=$!

wait "$pid_a" "$pid_b" "$pid_c"
echo "All tasks complete."

To check each task’s exit status, call wait separately for each saved PID. Save each PID with $! immediately after starting the task, because collecting PIDs later with jobs -p can miss tasks that have already finished and been removed from the job table. See our Bash wait guide for more examples of checking exit statuses.

The wait command accepts a job spec as well:

Terminal
wait %1

Quick Reference

For a printable quick reference, see the Job Control cheatsheet .

CommandDescription
jobsList all background and stopped jobs
jobs -lList jobs with PIDs
jobs -pPrint only PIDs
jobs -rList only running jobs
jobs -sList only stopped jobs
fg %1Bring job 1 to the foreground
bg %1Resume job 1 in the background
kill %1Terminate job 1
disown %1Remove job 1 from the job table
waitWait for all background jobs to finish

FAQ

What is the difference between jobs and ps?
jobs shows only the processes started from the current shell session. Use ps -e to list all processes on the system, regardless of which shell started them.

Why does jobs show nothing even though processes are running?
jobs only tracks processes started from the current shell. If you started a process in a different terminal or via a system service, it will not appear in jobs. Use ps aux to find it instead. Jobs removed with disown are also dropped from the list.

How do I stop a background job?
Use kill %N where N is the job number. For example, kill %1 sends SIGTERM to job 1. If the job does not stop, use kill -9 %1 to force-terminate it.

What do the + and - signs mean in jobs output?
The + marks the current job, the one that fg and bg will act on by default. The - marks the previous job. When the current job finishes, the previous job becomes the new current job. A stopped job stays current even when you start a newer job in the background.

How do I keep a background job running after closing the terminal?
Use nohup before the command, or disown after backgrounding it. For long-running interactive sessions, consider Screen or Tmux .

Conclusion

The jobs command lists all background and suspended processes in the current shell session. Use it together with fg, bg, and kill to control jobs interactively. For a broader guide on running and managing background processes, see How to Run Linux Commands in the Background .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page