Syllabus Topics :- The Linux Operating Systems Process: process abstraction, system calls for
process management, process creation: process states, data structures, process execution
mechanisms process api, process control and users
The Linux Operating System: Process Management Overview
In Linux, a process refers to a program in execution. The operating system uses process abstraction
to manage and allocate system resources. The goal is to provide a way to run multiple processes
concurrently while ensuring that each gets a fair share of the CPU, memory, and I/O devices.
Here's a breakdown of various aspects related to process management in Linux:
1. Process Abstraction
● Process: The basic unit of execution. A process is a running instance of a program and
includes:
○ Program code (text section)
○ Data (global variables, stack, heap)
○ Process Control Block (PCB): Stores the state of the process, program counter,
registers, etc.
● Process vs Thread: A process can contain one or more threads. A thread is a single sequence
of instructions within a process. Threads share resources of the process, such as memory, but
each has its own execution context.
2. System Calls for Process Management
System calls are the interface between user applications and the kernel. For process management,
some of the commonly used system calls include:
● fork(): Creates a new process by duplicating the calling process. The child process is a copy of
the parent.
● exec(): Replaces the current process image with a new one (used after a fork() to run a
different program).
● wait(): Makes the parent process wait until one of its child processes terminates.
● exit(): Terminates the calling process and sends an exit status to its parent.
● getpid(): Retrieves the process ID (PID) of the calling process.
● kill(): Sends a signal to a process. It can be used to terminate a process or communicate with
it.
3. Process Creation
Process creation in Linux involves the following steps:
● fork(): When a process calls fork(), a child process is created. The child process is a copy of
the parent, but they have separate memory spaces and their own PIDs.
● exec(): After fork(), the child process can call exec() to replace its memory space with a
new program, allowing it to run a different executable.
● init process: Every process is created as a descendant of the init process (PID = 1). It is
responsible for system startup and spawning other processes.
4. Process States
A process can exist in one of several states:
● New: The process is being created.
● Ready: The process is ready to run, waiting for the CPU to execute it.
● Running: The process is actively executing on the CPU.
● Waiting: The process is waiting for some event or resource, such as I/O completion or a signal.
● Terminated: The process has finished execution or has been killed. It is then cleaned up by
the kernel (zombie state) before being removed entirely.
5. Data Structures
In Linux, processes are represented by a Process Control Block (PCB), which contains crucial
information about a process. The PCB stores:
● PID: The unique process identifier.
● Parent PID (PPID): The process ID of the parent process.
● State: The current state of the process (running, waiting, etc.).
● Registers: The values of the CPU registers during the process's execution.
● Memory management information: Information about memory allocation for the process.
● File descriptors: A list of open files associated with the process.
● Scheduling information: Information used by the scheduler to decide when the process
should run.
These data structures are essential for managing and tracking processes in the system.
6. Process Execution Mechanisms
● Context Switching: The kernel periodically suspends one process and switches to another.
This process involves saving the state (context) of the current process and loading the state of
the next process. It's critical for multitasking.
● Scheduling: Linux uses several scheduling policies (such as Completely Fair Scheduler (CFS))
to determine which process gets CPU time next. The scheduler ensures fair distribution of
CPU time among all processes.
● Preemption: Linux is a preemptive multitasking system, which means that the kernel can
interrupt running processes to give CPU time to other processes if needed.
7. Process API
The Process API is an interface that allows programs to interact with processes. Some of the
common functions provided by the API include:
● fork(): Creates a new child process.
● exec(): Replaces the current process with a new program.
● waitpid(): Allows a parent process to wait for a specific child process to terminate.
● getpid(): Retrieves the PID of the current process.
● getppid(): Retrieves the PID of the parent process.
8. Process Control
Process control refers to the actions that can be taken to manage processes, including:
● Termination: A process can be terminated through system calls like exit() or signals like
kill(). The termination can be either normal (successful completion) or abnormal (due to a
crash or manual intervention).
● Signals: A signal is a message sent to a process to notify it of an event. Signals can be used for
inter-process communication (IPC) or to control process execution (e.g., SIGTERM, SIGKILL).
9. User Interaction with Processes
Linux allows users to interact with processes in a variety of ways:
● ps: Displays the current processes.
● top: Displays a real-time view of running processes, including CPU and memory usage.
● kill: Sends signals to a process, often used to terminate processes.
● nice: Changes the priority of a process.
● strace: Traces system calls made by a process, useful for debugging.
Summary
Process management in Linux is a sophisticated mechanism that ensures processes run
concurrently and efficiently. Linux provides system calls, data structures, and process states to
manage these processes. The process API allows interaction between user programs and the kernel
to create, control, and terminate processes. Understanding these mechanisms is key to
understanding how Linux handles multitasking, scheduling, and inter-process communication.
—--------------------------------------------------------------------------------------------------
1. Process Abstraction in Linux
In Linux, a process is an instance of a running program. The OS abstracts and manages each
process separately, assigning resources like memory, CPU time, and I/O.
Key Elements of a Process:
● PID (Process ID): Unique identifier
● Memory space: Includes code, data, stack, and heap
● Registers and Program Counter
● Open file descriptors
● Parent process ID (PPID)
Example:
When you run a program like:
bash
CopyEdit
gedit file.txt
The Linux kernel creates a new process for gedit with a unique PID.
⚙️ 2. System Calls for Process Management
System calls are kernel-level services accessible by user programs to perform operations like
creating or killing processes.
Common System Calls:
System Call Description
fork() Creates a new process (child)
exec() Replaces current process with a new
program
wait() Makes parent wait for child to finish
exit() Terminates the process
getpid() Returns process ID
kill() Sends signal to process (e.g., terminate)
Example in C:
C lang:-
#include <unistd.h>
#include <stdio.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
printf("This is the child process\n");
} else {
printf("This is the parent process\n");
return 0;
3. Process Creation in Linux
Linux uses a parent-child model for creating processes.
Steps:
1. Parent calls fork() – a child is created as a copy.
2. Child calls exec() (optional) to load a new program.
3. Parent can call wait() to wait for the child.
Example:
bash
CopyEdit
bash$ sleep 100 &
[1] 3456 # PID 3456
The sleep command becomes a background process.
🔄 4. Process States
A process transitions between several states during its lifetime:
State Description
Running Currently executing on CPU
Ready Ready to run, waiting for CPU
Waiting Waiting for I/O or event
Stopped Suspended (e.g., with Ctrl+Z)
Zombie Finished but not cleaned up
Terminated Completed execution
Example:
● Run ps -el to view process states (look under the “STAT” column).
🧾 5. Data Structures in Linux (Kernel-level)
Linux maintains internal data structures to track processes:
task_struct
Defined in the kernel, holds all process info.
Important fields:
● pid: Process ID
● state: Current state
● mm: Memory info
● files: Open files
● parent: Pointer to parent process
Example:
You can view process details with:
bash
CopyEdit
cat /proc/1234/status
⚙️ 6. Process Execution Mechanism
Context Switching
● The kernel switches from one process to another.
● Saves current state and loads the next.
Scheduler
● The Linux scheduler (CFS) picks which process to run next.
● Scheduling policies:
○ SCHED_NORMAL: Default for most processes
○ SCHED_FIFO, SCHED_RR: For real-time
○ nice: Sets priority (-20 to 19)
Example:
bash
CopyEdit
nice -n 10 ./heavy_process
🔌 7. Process API (Interaction & Monitoring)
Common tools and functions:
API/Tool Purpose
ps, top, htop View running processes
kill, killall Send signals
strace Trace system calls
nice, renice Adjust priority
Example:
bash
CopyEdit
ps aux | grep firefox
kill -9 1234 # Forcefully kill Firefox
🛂 8. Process Control and Users
Linux controls process ownership and permissions:
Each process has:
● UID (User ID) – who owns it
● GID (Group ID) – which group it belongs to
Only the owner or root can:
● Kill or renice the process
● Debug or trace it
Example:
bash
CopyEdit
ps -u username # Show processes by a specific user
✅ Summary
Component Description
Process Abstraction Encapsulates program execution
System Calls fork(), exec(), wait() etc.
Process States Running, Waiting, Zombie, etc.
Data Structures task_struct in kernel
Execution Mechanism Context switching, scheduling
Process API Tools and interfaces like ps, kill
User Control UID/GID manage permissions
● Process Creation Flowchart
●
🔄 Linux Process States Diagram
State Description
New Process is being created
Ready Waiting to be scheduled
Running Currently executing
Waiting Waiting for I/O or event
Zombie Finished execution but not yet cleaned by
parent
Exit Process is terminated and about to be
cleaned up