Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Processes and Signals

Bash jobs command

Reference for the Bash jobs builtin: list background and stopped jobs, read the job table, show process IDs, filter by state and refer to jobs with %1, %% and %+.

jobs is a Bash builtin that lists the jobs the current shell is managing: commands you started with &, or stopped with Ctrl+Z. A job is a pipeline the shell started and keeps track of; each gets a small number ([1], [2]) that you use with fg, bg, kill and wait.

Jobs belong to one shell. A second terminal, or a script that started its own children, has its own list, and jobs never shows processes started by other shells. When a job has finished, jobs reports it once as Done and then forgets it.

Terminal
jobs [-lnprs] [JOBSPEC...]

Try it

Bash Starting jobs and listing them

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Job states and filters

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
jobs [-lnprs] [-x COMMAND [ARGS]] [JOBSPEC ...]
Option Description
-l Long format: also show process IDs.
-p Print only the process IDs (the process group leader of each job).
-n Only jobs whose status changed since the last notification.
-r Only running jobs.
-s Only stopped jobs.
-x CMD Replace each jobspec in CMD with its process ID, then run it.
Job specification Meaning
%N Job number N.
%%, %+ The current job (the most recently started or stopped one, marked +).
%- The previous job (marked -).
%string The job whose command begins with string.
%?string The job whose command contains string.

Returns: 0, or non-zero if a given jobspec does not exist.

Usage notes

  • Interactive shells only for the full feature set. In a script job control is off by default, so Ctrl+Z, fg and bg do not work unless you run set -m. Background jobs and jobs still work.
  • The number is not the process ID. [1] is the job number; the PID is shown by jobs -l or in $! right after starting a job.
  • Pipelines are one job. sort big | uniq > out & is job [1] even though it has two processes. jobs -p prints the leader's PID.
  • Done is shown once. After a job finishes, the next jobs (or the next prompt) reports it and removes it from the table.
  • Leaving the shell. Closing a terminal sends SIGHUP to the jobs. Use nohup or disown to keep them alive.
  • A subshell has no jobs. $(jobs) and ( jobs ) inside the shell list nothing from the parent in most cases; run jobs in the main shell.
  • Differences: in dash (/bin/sh) the output format differs, and disown does not exist.