LinuxCommandLibrary

jobs

List background jobs

TLDR

Show status of all jobs

$ jobs
copy

Show status of a particular job
$ jobs %[job_id]
copy

Show status and process IDs of all jobs
$ jobs -l
copy

Show process IDs of all jobs
$ jobs -p
copy

SYNOPSIS

jobs [-lnprs] [jobspec ...]

PARAMETERS

-l
    Displays more information, including the Process ID (PID) of each job.

-n
    Lists only jobs whose status has changed since the last notification.

-p
    Shows only the Process ID (PID) of each job, without any other information.

-r
    Restricts the display to only running jobs.

-s
    Restricts the display to only stopped jobs.

[jobspec ...]
    Specifies one or more jobs to display. A job can be specified by its job number (e.g., %1), a string prefix of its command name (e.g., %vim), or special symbols like %% or %+ for the current job, and %- for the previous job.

DESCRIPTION

The jobs command is a shell built-in that displays the status of jobs started in the current shell session. It allows users to monitor processes that have been suspended (stopped) or are running in the background. Each job is assigned a unique job number within the shell, distinct from its Process ID (PID). jobs provides an overview of these backgrounded or stopped tasks, showing their state (e.g., 'Running', 'Stopped', 'Done') and the command line that initiated them. This command is crucial for job control, enabling users to manage multiple concurrent tasks within a single terminal session, often in conjunction with commands like fg (foreground) and bg (background). It helps maintain an organized and efficient interactive shell environment.

CAVEATS

The jobs command is a shell built-in, meaning its exact behavior and available options can vary slightly between different shells (e.g., Bash, Zsh, Dash). It only displays jobs associated with the current shell session; it cannot list processes or jobs started from other terminals or system-wide daemon processes.

JOB CONTROL OVERVIEW

Job control is a feature of Unix shells that allows a user to control the execution of processes. It enables the user to stop, background, or foreground processes launched from the shell. The jobs command is the primary tool for viewing the state of these controlled processes.

JOB ID VS. PID

When a command is sent to the background or stopped, the shell assigns it a 'job ID' (e.g., [1], [2]). This ID is distinct from the system's Process ID (PID). Job IDs are unique to the current shell session and are used for shell built-ins like fg, bg, and kill (when specifying jobspecs), while PIDs are system-wide unique identifiers for processes.

OUTPUT FORMAT

By default, jobs displays each job with its job ID (e.g., [1]), its status (e.g., 'Running', 'Stopped', 'Done'), and the command line that was executed. If the -l option is used, the Process ID (PID) is also included. The '+' symbol indicates the current job (the one that would be affected by fg or bg without arguments), and '-' indicates the previous job.

HISTORY

Job control, including the concept of background jobs and the ability to list them via commands like jobs, was a significant enhancement introduced in Unix-like operating systems, notably with the 4.1BSD release. This feature allowed users to manage multiple processes from a single terminal, suspending and resuming tasks as needed. The jobs command has since become a standard and integral part of all POSIX-compliant shells, reflecting its fundamental role in interactive shell management.

SEE ALSO

fg(1), bg(1), kill(1), ps(1), nohup(1)

Copied to clipboard