USD ($)
$
United States Dollar
Euro Member Countries
India Rupee

Process Control and Termination

Lesson 27/49 | Study Time: 20 Min

In Linux, effective process control and termination are crucial for managing system resources and ensuring smooth operation. Users and administrators often need to pause, resume, or terminate processes based on system demands or troubleshooting needs. Linux provides a rich set of commands and signals to control running processes, facilitating graceful shutdowns or immediate termination when necessary. 

Process Control Basics

Efficient multitasking in Linux depends on understanding process control. Below is a list of essential job control concepts and commands.


1. Foreground and Background Processes:


  • Foreground processes run interactively with terminal input/output.
  • Background processes run independently, freeing the terminal for other tasks.


2. Job Control Commands:


  • bg: Resume a suspended process in the background.
  • fg: Bring a background or suspended job to the foreground.
  • jobs: List current jobs started by the terminal session with their states (running, stopped).


Example:

bash
$ sleep 500
^Z
[1]+ Stopped sleep 500
$ bg 1
[1]+ sleep 500 &

Signals for Process Management

Linux processes respond to signals—notifications sent to trigger actions like termination or suspension.

Sending Signals to Processes

Sending signals helps suspend, resume, or terminate running processes. Following are the Linux commands used for process signaling.


1. kill Command: Sends signals to specific processes by PID.

Usage:

text
kill PID # sends SIGTERM by default
kill -9 PID # sends SIGKILL to force termination
kill -s SIGSTOP PID # suspends process


2. killall Command: Sends a signal to all processes by name.

Usage:

text
killall processname
killall -9 processname


3. pkill Command: Similar to killall but with more pattern matching options.

Suspending and Resuming Processes

Suspending a process frees the terminal without stopping execution permanently. The following commands explain how to pause and continue processes.


  • Suspend current foreground process: Press Ctrl+Z.


  • List suspended and background jobs:
text
jobs


  • Resume job in background:
text
bg %job_number


  • Resume job in foreground:
text
fg %job_number

Practical Example Workflow


1. Start a long-running command:

text
tar -czvf backup.tar.gz /home/user


2. Suspend it: press Ctrl+Z.

3. View jobs:

text
jobs


4. Resume it in background:

text
bg %1


5. If needed, terminate forcefully:

text
kill -9 PID
Samuel Wilson

Samuel Wilson

Product Designer
Profile

Class Sessions

1- What is Linux and Operating System Concepts 2- Linux History and Evolution 3- Linux Distributions and Their Purposes 4- Open Source Software and Licensing 5- Graphical User Interface (GUI) and Desktop Environments 6- Terminal Access and Command-Line Fundamentals 7- Getting Help and Command Documentation 8- File System Hierarchy and Directory Structure 9- Navigating Directories and Listing Contents 10- Creating, Copying, and Moving Files and Directories 11- Deleting Files and Directories 12- Symbolic and Hard Links 13- Understanding File Permissions Model 14- Modifying Permissions and Ownership 15- User and Group Management 16- Sudo and Privilege Escalation 17- Text Searching and Pattern Matching 18- Text Processing and Stream Editing 19- Compressing and Archiving Files 20- Text Editing and File Creation 21- Package Management Systems Overview 22- Installing and Updating Software with APT 23- Installing and Updating Software with YUM/DNF 24- Managing Software from Non-Repository Sources 25- Understanding Processes and Process Management 26- Viewing Running Processes 27- Process Control and Termination 28- Task Scheduling with Cron 29- Networking Concepts and IP Addressing 30- Viewing and Configuring Network Interfaces 31- Basic Network Troubleshooting 32- Shell Script Basics 33- Variables and Data Types 34- Conditional Logic in Scripts 35- Loops and Iteration 36- Functions and Code Reuse 37- Input/Output and User Interaction 38- System Authentication and Access Control 39- File System Security 40- Software Updates and Patching 41- Basic Firewall Concepts 42- System Information and Monitoring 43- Service and Daemon Management 44- System Boot Process and Runlevels 45- System Backup and Disaster Recovery 46- Comprehensive File System Management 47- System Automation Workflows 48- Multi-Concept Troubleshooting Scenarios 49- Continued Learning Pathways