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

Understanding Processes and Process Management

Lesson 25/49 | Study Time: 20 Min

In Linux, a process is an instance of a running program. Managing these processes efficiently is crucial for ensuring system performance, stability, and security. Processes can be applications, services, or background tasks, each identified by a unique process ID (PID). Linux provides comprehensive tools and commands to monitor, control, prioritize, and troubleshoot processes. 

What is a Process in Linux?

A process represents a running program with an associated state, memory allocation, and execution context. Each process has a unique process ID (PID) and is created by the kernel when a program is executed.


Processes can be:


1. Foreground processes: Interact directly with the user.

2. Background processes: Run independently without user interaction.


Parent processes spawn child processes, forming a tree hierarchy managed by the kernel.

Process States

Linux processes transition through several states during their lifecycle:

Monitoring Processes

Multiple commands allow examining processes:


1. ps (Process Status): Lists currently running processes with details like PID, user, CPU time, and command.

Example: ps aux displays all processes.

2. top: Interactive real-time process monitoring showing CPU, memory usage, and process hierarchy.

3. htop: User-friendly top alternative with visual enhancements.

4. pidof, pgrep: Search for processes by name and return their PIDs.

Controlling Processes

Linux allows precise control over process execution and termination. Following are the key methods used to manage processes.


1. Foreground and Background:


  • Run processes in background with & (e.g., sleep 60 &).
  • Bring background job to foreground: fg.
  • Send process to background: bg.


2. Signals and Termination: Use kill to send signals to processes.


Common signals:


SIGTERM (15): Graceful termination.

SIGKILL (9): Forceful termination.

SIGSTOP: Suspend process.

SIGCONT: Resume process.


Example: kill -9 12345 kills process with PID 12345.


3. killall and pkill: Kill processes by name rather than PID.

Prioritizing Processes

Nice value: Sets process priority (-20 highest, 19 lowest).

Use nice to start a process with a specified priority:

text
nice -n 10 command

Modify priority of a running process with renice:

text
sudo renice -n 5 -p 12345

Process Lifecycle and Zombies


1. When a process terminates, it becomes a zombie if its parent does not read its exit status, occupying system resources.

2. Orphan processes are re-parented to the init process (PID 1) which cleans zombies.

3. Proper process control ensures resources are freed and avoids system slowdowns.

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