Job Control Commands - Manage Processes in Shell | Online Free DevTools by Hexmos

Master job control commands like jobs, fg, bg, kill, and stop to manage processes in your shell. Learn to suspend, resume, and terminate jobs effectively.

Job Control Commands

Understanding Shell Job Control

The command line provides the powerful ability to stop (suspend) the execution of a process and resume a suspended process at a later point in time. Each running program is referred to as a job, and a unique ID is assigned to every job for easy management.

Key Job Control Commands

Here's a breakdown of essential commands for managing your shell jobs:

Command Description
jobs Lists all the jobs that the current shell is running or has suspended.
fg Brings a suspended or background job to the foreground for interactive use.
bg Sends a suspended job to the background, allowing you to continue using the terminal.
kill Terminates a specified job.
stop Suspends the execution of a running job.
Ctrl+c Interrupts and terminates the currently running foreground job.
Ctrl+z Suspends the currently running foreground job, sending it to the background.

Running Jobs in the Background

To start a job in the background immediately, append an ampersand (&) to the end of your command.

Examples of Job Control Usage

  • Start a job in the background:
    sleep 1000 &
  • Bring a job to the foreground:
    fg %2 # where 2 is the job number
  • Suspend a running job:
    stop %2 # where 2 is the job number
  • Resume a suspended job in the background:
    bg %2 # where 2 is the job number
  • Terminate a job:
    kill %2 # where 2 is the job number

Further Reading on Process Management

For a deeper understanding of how processes and job control work in Unix-like systems, you can refer to the following resources: