Unit 9: Introduction to Process | Operating Systems

A process is one of the core concepts of an Operating System. It represents a program that is currently being executed by the system.
1. What is a Program?
A program is a set of instructions written to perform a specific task.
When the program is compiled and ready to execute, it is stored as an executable file.
Program = Compiled code ready for execution
2. What is a Process?
A process is a program under execution.
When the Operating System loads a program into memory and starts its execution, it becomes a process.
Program
↓
Loaded into Memory
↓
Execution
↓
Process
Example
Chrome.exe → Program
Chrome running → Process
3. How Does the OS Create a Process?
The Operating System converts a program into a process by preparing the required memory, resources, and execution environment.
Steps
Program
│
▼
Load Program & Static Data
│
▼
Allocate Runtime Stack
│
▼
Allocate Heap
│
▼
I/O Tasks
│
▼
Start Execution
│
▼
main()
a. Load the Program & Static Data into Memory
The OS loads the program instructions and static data into the process's memory space.
b. Allocate Runtime Stack
A runtime stack is created for function calls, local variables, return addresses, and related execution information.
c. Heap Memory Allocation
Memory required for dynamic allocation is made available through the process's heap.
d. I/O Tasks
The OS prepares the process to perform required Input/Output operations, such as file access and device interaction.
e. OS Hands Off Control
After initialization, the OS starts the program's execution, eventually reaching the program's main() function in a typical C/C++ program.
4. Architecture of a Process
A process mainly consists of its program code, data, heap, stack, and execution information.
Process Memory
┌─────────────────────────┐
│ Stack │
│ Function Calls │
├─────────────────────────┤
│ │
│ Free Space │
│ │
├─────────────────────────┤
│ Heap │
│ Dynamic Allocation │
├─────────────────────────┤
│ Data │
│ Global & Static Data │
├─────────────────────────┤
│ Code / Text │
│ Program Instructions │
└─────────────────────────┘
5. Attributes of a Process
Process attributes are the information used by the Operating System to identify and manage a process.
a. Process Identification
Each process needs an identifier that allows it to be uniquely distinguished from other processes.
The most important identifier is:
Process ID (PID)
Example:
Process A → PID 101
Process B → PID 102
Process C → PID 103
b. Process Table
The Operating System tracks all active processes using a process table.
Process Table
┌─────────┬─────────────────┐
│ PID │ PCB │
├─────────┼─────────────────┤
│ 101 │ PCB → P1 │
│ 102 │ PCB → P2 │
│ 103 │ PCB → P3 │
└─────────┴─────────────────┘
Each entry contains the information required to manage a particular process.
c. Process Control Block (PCB)
A Process Control Block (PCB) is a data structure maintained by the OS for each process.
It stores important information such as:
Process ID (PID)
Process State
Program Counter
CPU Registers
Priority
Scheduling Information
Memory Information
I/O Information
6. PCB Structure
A simplified PCB can be represented as:
┌─────────────────────────────┐
│ Process Control Block │
├─────────────────────────────┤
│ Process ID (PID) │
│ Process State │
│ Program Counter │
│ CPU Registers │
│ Process Priority │
│ Scheduling Information │
│ Memory Information │
│ I/O Information │
└─────────────────────────────┘
Role of Registers in PCB
The PCB stores the CPU context required to resume a process.
When a process is running and its time slice expires, the current values of its CPU registers are saved as part of its context. The process is then switched out.
Process P1 Running
↓
Time Slice Expires
↓
Save CPU Context
↓
PCB of P1
↓
Process Switched Out
When the process is scheduled again, the saved register values are restored to the CPU.
PCB of P1
↓
Restore CPU Registers
↓
CPU
↓
P1 Resumes Execution
This is an important part of context switching.
Main purpose: The register information in the PCB helps the OS save and restore the execution context of a process so that it can continue from where it was interrupted.



