jobs Command

The jobs command in Linux is a shell built-in command that lists the active jobs (processes) that are running in the current shell session. These jobs can be running in the foreground, in the background, or stopped.

Syntax

jobs [-l|-p] [jobspec...]

Description

The jobs command is part of job control in Unix-like operating systems, which allows users to manage multiple processes from a single shell. It provides information about the state of these jobs, including their job number, process ID (PID), and status (running, stopped, done).

Common uses include:

  • Listing all active jobs in the current shell.
  • Identifying background processes.
  • Checking the status of suspended jobs.
  • Managing jobs with fg (foreground) and bg (background) commands.

Common Options

Option Description
-l List process IDs in addition to the normal information.
-p List only the process ID of the job's process group leader.
-r Restrict output to running jobs.
-s Restrict output to stopped jobs.

Examples

List all active jobs

jobs
# Example Output: # [1]- Stopped vim # [2]+ Running sleep 600 &

Displays all jobs, including stopped and background processes.

List jobs with their process IDs

jobs -l
# Example Output: # [1]- 12345 Stopped vim # [2]+ 12346 Running sleep 600 &

Shows the PID for each job in addition to the standard output.

Bring a background job to the foreground

fg %1

Brings job number 1 (as listed by jobs) to the foreground.

Send a suspended job to the background

# (Press Ctrl+Z on a running foreground process to suspend it) bg

Sends the most recently suspended job to the background.

Kill a background job

kill %2

Terminates job number 2.

See also