Jobs and Job Control in Linux

In the Linux operating system, jobs refer to processes that are running in the background or foreground. Job control refers to the ability to manipulate these processes, including suspending, resuming, and terminating them. This feature enables users to manage multiple tasks efficiently and debug process-related issues.

Job control is made possible by the shell, which is a command-line interface that allows users to interact with the operating system. The most common shell in Linux is the Bourne Again Shell (BASH), but other shells such as the Z Shell (ZSH) and the Korn Shell (KSH) also support job control features.

Understanding Processes and Jobs in Linux

In Linux, every running program is considered a process. Each process is assigned a unique identifier called a Process ID (PID), which can be used to reference and perform actions on the process.

A job is a process or a group of processes that can run either in the foreground or background:

  • Foreground jobs Run interactively in the current terminal session and block further input until completion

  • Background jobs Run independently without blocking the terminal, allowing users to continue entering commands

Job States in Linux Running Stopped Terminated Ctrl+Z fg/bg kill Ctrl+C / kill

To run a process in the background, append the & symbol to the command:

sleep 30 &
[1] 12345

The output shows [1] as the job number and 12345 as the process ID.

Job Control Commands

Command Purpose Example Usage
jobs List active jobs jobs -l
fg Bring job to foreground fg %1
bg Send job to background bg %1
kill Terminate job kill %1
Ctrl+Z Suspend foreground job Interactive keystroke
Ctrl+C Terminate foreground job Interactive keystroke

Managing Jobs with fg and bg

Use fg to bring a background job to the foreground:

fg %1

To send a job to the background, first suspend it with Ctrl+Z, then use bg:

sleep 30
# Press Ctrl+Z to suspend
bg %1
[1]+ Stopped    sleep 30
[1]+ sleep 30 &

Viewing Jobs and Processes

The jobs command displays all jobs in the current shell session:

jobs -l
[1]  12345 Running    sleep 30 &
[2]- 12346 Stopped    vim file.txt
[3]+ 12347 Running    ping google.com &

The ps command shows all system processes with detailed information:

ps aux | head -5
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 225868  9208 ?        Ss   Jan01   0:02 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan01   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        I<   Jan01   0:00 [rcu_gp]
user     12345  0.0  0.0   7352   796 pts/0    S    10:30   0:00 sleep 30

Job Identification Methods

Jobs can be referenced using several methods:

  • %n Job number (e.g., %1, %2)

  • %+ or %% Current job (most recent)

  • %- Previous job

  • %string Job whose command begins with string

  • PID Process ID number

Conclusion

Job control in Linux provides powerful process management capabilities through shell commands like jobs, fg, bg, and kill. Understanding these tools enables efficient multitasking and system administration. Mastering job control is essential for effective Linux command-line usage and process troubleshooting.

Updated on: 2026-03-17T09:01:38+05:30

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements