RedTeam Nexus Labs
Module 05 · Lesson 05 // Processes

jobs

Processes · Linux

Freereading · 10 min
On this page
LESSON

Overview

Within a single shell you can run multiple commands and control them as jobs — running some in the background, bringing others to the foreground, and pausing or resuming them. Job control makes the terminal far more productive. This lesson explains jobs.

Learning objectives

  • Explain foreground vs background jobs.
  • Use job-control commands to manage them.
  • Keep processes running after logout when needed.

Core concept

A job is a command (or pipeline) managed by the shell. Job control lets you run more than one thing from a single terminal:

  • Foreground — the job occupies the terminal until it finishes.
  • Background — the job runs while you keep using the terminal, started by appending &.
  • Suspend — Ctrl+Z pauses the foreground job (stops it, does not kill it).

Key commands: jobs (list this shell's jobs), bg (resume a suspended job in the background), fg (bring a job to the foreground).

How it works

Append & to launch a command in the background so the shell prompt returns immediately (e.g. long-task &). Press Ctrl+Z to suspend the current foreground job; then bg resumes it in the background or fg brings it back to the foreground. jobs shows the jobs and their numbers, which you reference as %1, %2, etc. Note that jobs are tied to the shell — closing the terminal normally ends them (unless detached), which is where tools below help.

Practical example

$ long-scan &            # start in background; prompt returns
[1] 2453
$ jobs
[1]+  Running   long-scan &
$ fg %1                  # bring job 1 to the foreground
^Z                       # Ctrl+Z suspends it
$ bg %1                  # resume it in the background

To keep a task running after logout, you would detach it — e.g. with nohup long-scan & or a terminal multiplexer like tmux/screen — so it survives the session ending.

Cybersecurity relevance

Job control and detachment are practical for long-running security tasks: a lengthy scan or capture (in an authorized engagement) can run in the background or be detached with tmux/nohup so it continues even if the SSH session drops. Understanding that ordinary background jobs die with the shell — but detached ones persist — helps you run tasks reliably. Note that only authorized activity is appropriate; job control is simply the mechanism for managing it.

Common mistakes

  • Expecting a plain background job to survive logout — it typically ends with the shell; use nohup/tmux to persist.
  • Confusing suspend (Ctrl+Z) with terminate (Ctrl+C) — Ctrl+Z pauses, Ctrl+C ends.
  • Losing track of background jobs — use jobs to list them.

Key takeaways

  • A job is a shell-managed command; run in the foreground, in the background (&), or suspend with Ctrl+Z.
  • Manage jobs with jobs (list), bg (resume in background), and fg (bring to foreground), referenced as %1, %2, etc.
  • Plain background jobs end with the shell; use nohup or tmux/screen to keep long-running (authorized) tasks alive after logout.

Check your understanding

  • What is the difference between pressing Ctrl+Z and Ctrl+C on a running foreground job?
  • How can you keep a long-running task alive after your terminal session ends?
FINISH THIS LESSON

Sign in to save your progress.