Home > Process Management > jobs

jobs: Manage Background Jobs

The `jobs` command is used to check the status of background jobs running in the current shell. It displays the job number, status, command, and more, allowing for efficient management of multiple tasks.

Overview

In Linux, you can run multiple tasks simultaneously in a single terminal. The `jobs` command lists the jobs running within the current shell session, showing which jobs are running in the background or are stopped. This allows users to control the state of jobs using commands like `fg` (bring to foreground) or `bg` (run in background). `jobs` is especially useful when executing long-running tasks without tying up the terminal. If `jobs` produces no output, it means there are no jobs currently running in the background or temporarily stopped.

Key Features

The main features of the `jobs` command are:

  • Shows background jobs running in the current shell.
  • Allows individual jobs to be identified by their job number.
  • Displays the status of jobs (running, stopped, done, etc.).
  • Used to control jobs with commands like `fg` or `bg`.

Job Statuses

The `jobs` command can output the following job statuses:

  • Running: The job is currently executing in the background.
  • Stopped: The job is temporarily suspended. You can stop it by pressing `Ctrl+Z`.
  • Done: The job has completed successfully.
  • Terminated: The job has terminated abnormally.

Key Options

Commonly used `jobs` command options are grouped by purpose.

1) Output Options

2) Help

Generated command:

Try combining the commands.

Description:

`jobs` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Explore the various functionalities of the `jobs` command through examples.

Start and Check Background Job

sleep 60 &
jobs

Run `sleep 60` in the background (`&`), then check its status with `jobs`.

Suspend and Check a Job

ping google.com
(Ctrl+Z 입력)
jobs

Run the `ping` command, press `Ctrl+Z` to suspend it, then check its status with `jobs`.

Run a Suspended Job in Background

bg %1

Using `bg` command, resume a suspended job (`Stopped`) identified by `jobs` in the background.

Bring a Background Job to Foreground

fg %2

Using `fg` command, bring a running job (`Running`) identified by `jobs` to the foreground.

List Jobs with PID

jobs -l

Use the `-l` option to display job number, status, and PID together.

Installation

`jobs` is a built-in command of the shell (bash, zsh, etc.) and does not require separate installation.

Tips & Considerations

Important points to note when using the `jobs` command.

Tips

  • Use the `&` symbol to run a command in the background (e.g., `long_running_script.sh &`).
  • `Ctrl+Z` is a shortcut to temporarily suspend (stop) the currently running foreground job. A suspended job can be resumed with `bg` (background) or brought back to the foreground with `fg`.
  • `jobs` only shows tasks initiated in the current shell. To view tasks running in other terminals, you should use the `ps` command.

Related commands

These are commands that are functionally similar or are commonly used together.


Same category commands