This document explains the jobs
command, which is part of Job control
in UNIX
and UNIX LIKE
systems.
The jobs
command is used to check the jobs that are currently running in the background
of the current shell
.
In comparison to Windows
,
jobs
is similar to checking the programs that are running in the background
, minimized and not visible in the foreground
, akin to the taskbar
.
π΅ NOTE
In UNIX, a
Job
refers to a collection ofProcesses
. The PID of a job refers to theProcess Group ID
.
π΅ NOTE
This was tested using
zsh
on MacOS, Sonoma.
zsh
has extended features, and more information can be found inman zshbuiltins
.
π΅ NOTE
This document is a translation of the
jobs
description fromThe Open Group Base Specifications Issue 7
, provided by the official UNIX group,THE Open GROUP
, and briefly explains the parts that users need to know.
[ ]
(brackets) are optional.|
(pipe) indicates that one of several options can be chosen....
(three dots) indicates that multiple arguments can be specified.jobs [-l| -p][job_id...]
-l
(lowercase L) provides more information about each listed job. This information includes the job number, current job, process group ID, state, and the command that formed the job.
-p
displays only the process ID of the process group leader for the selected job.
job_id
job_id
is specified, status information for all jobs will be displayed. The format of job_id
is described in XBD Job Control Job ID
.If the -p
option is specified,
the output consists of one line for each process ID.
"%d\n", <process ID>
If the -l option
is not specified,
the output consists of a series of lines in the following format.
"[%d] %c %s %s\n", <job-number>, <current>, <state>, <command>
Where the fields are as follows:
<job-number>
wait
, fg
, bg
, and kill
utilities.%
.<current>
+
identifies the job that will be used as the default for the fg
or bg
utilities.job_id %+
or "%%"
.-
identifies the job that will become the default when the current default job terminates.job_id %-
.space
.+
, and at most one job can be identified with -
.<state>
One of the following strings (in POSIX locale
):
Running
Done
0
.Done(code)
code
.Stopped
SIGTSTP
signal.Stopped (SIGTSTP)
SIGTSTP
signal.Stopped (SIGSTOP)
SIGSTOP
signal.Stopped (SIGTTIN)
SIGTTIN
signal.Stopped (SIGTTOU)
SIGTTOU
signal.<command>
If the -l option
is specified,
a field containing the process group ID is inserted before the <state>
field.
Additionally, more processes within the process group may be output on separate lines, using only the process ID and <command>
fields.
First, enter a command in the shell
to create a simple job
.
sleep 100 &
This command runs sleep
, which waits for 10 minutes and then terminates, in the background
using &
(ampersand).
π΅ NOTE
&
(ampersand) is the command to run a process in the background in the current session.
The result of running the jobs
command with no options is as follows.
Command input
jobs
Output
[1] + 12345 Running sleep $((60 * 10)) &
The result of running the jobs
command using zsh
is as follows.
In zsh
, when a job
terminates, Done
is displayed.
π£ IMPORTANT
zsh 5.9 (x86_64-apple-darwin23.0)
has a bug where using jobs -p
should output only the process numbers, but it behaves the same as the -l
option.
In contrast, bash
correctly outputs only the process numbers with jobs -p
.