Session 2.1: Process Fundamentals
Understanding processes, programs, process states, and basic scheduling concepts
Learning Objectives
By the end of this session, you will be able to:
- Distinguish between programs and processes
- Identify process components and memory layout
- Explain process states and transitions
- Understand Process Control Block (PCB)
- Describe basic process scheduling concepts
- Analyze context switching mechanisms
Key Concept
A process is a program in execution - the fundamental unit of work in modern computing systems. It transforms from a passive program into an active entity when loaded into memory.
Program vs Process
Program
- Passive Entity: Static blueprint
- Storage: File on disk (executable)
- State: Unchanging instructions
- Examples: Word processor, compiler, web browser
- Resources: No resources allocated
Definition: A file containing a list of instructions stored on disk, representing executable code.
Process
- Active Entity: Dynamic instance in action
- Location: Loaded in memory
- State: Changes during execution
- Instances: Multiple processes from same program
- Resources: CPU time, memory, files, I/O
Definition: A program in execution - the fundamental unit of work in modern computing systems.
Key Distinction
When an executable file is loaded into memory, it transitions from being a passive program to an active entity – a process. Multiple processes can be associated with the same program, but each is a separate execution sequence.
Process Components and Memory Layout
A process includes:
- Program Counter: Specifies the next instruction to execute
- CPU Registers: Current values of processor registers
- Memory Sections: Organized layout in memory
- Resources: Files, I/O devices, etc.
Process Execution:
- Single-threaded: One program counter, sequential execution
- Multi-threaded: Multiple threads, concurrent/parallel execution
Memory Layout
Local variables, function calls
Dynamically allocated memory
Global variables
Executable code
Process States
As a process executes, it changes state. The state of a process is defined by its current activity.
Five Fundamental Process States
NEW
The process is being created and initialized.
READY
Process is prepared to execute but waiting to be assigned to a processor. Multiple processes can be ready concurrently.
RUNNING
Instructions are currently being executed by a CPU core. Only one process per core can be running at any instant.
WAITING
Process is temporarily paused, awaiting a specific event (I/O completion, signal reception, child termination).
TERMINATED
Process has completed its execution and resources are being deallocated.
Process State Transitions
Processes migrate between states throughout their lifetime. The operating system manages these transitions to optimize CPU utilization.
Typical State Transition Flow
- NEW → READY: Process is admitted into the system
- READY → RUNNING: CPU scheduler selects and dispatches process
- RUNNING → WAITING: Process requests I/O or waits for event
- RUNNING → READY: Process is preempted (time slice expires, interrupt)
- RUNNING → TERMINATED: Process completes execution
- WAITING → READY: Event occurs (I/O completion, signal received)
Process State Mind Map
PROCESS STATES
|
|-- DEFINITION: Current activity status of a process
|
|-- FIVE FUNDAMENTAL STATES
| |-- NEW (Process is created)
| | |-- Admitted → READY
| |
| |-- READY (Waiting for CPU)
| | |-- Scheduler Dispatch → RUNNING
| |
| |-- RUNNING (Executing instructions)
| | |-- Exit → TERMINATED
| | |-- I/O Request/Wait for Child → WAITING
| | |-- Time Slice Expired/Interrupt → READY
| |
| |-- WAITING (Paused, awaiting event)
| | |-- I/O Completion/Event/Child Termination → READY
| |
| |-- TERMINATED (Execution finished)
|
|-- MANAGED BY
| |-- CPU Scheduler (selects processes)
| |-- Dispatcher (performs context switch)
| |-- Operating System (manages queues)
|
|-- QUEUES
|-- Ready Queue (processes waiting for CPU)
|-- Wait Queues (processes waiting for events)
Process Control Block (PCB)
Each process is formally represented within the operating system by a Process Control Block (PCB), also known as a task control block.
PCB Purpose
The PCB serves as a central repository for all information needed to start, pause, or restart a process.
PCB Contains:
Process State
Current state (new, ready, running, waiting, terminated)
CPU Information
- Program counter value
- CPU register contents
CPU Scheduling Info
- Process priority
- Scheduling queue pointers
Memory Management
- Base and limit registers
- Page tables
Accounting Information
- CPU time used
- Time limits
I/O Status
- List of open files
- I/O devices allocated
Process Scheduling
Process scheduling is a fundamental OS function that selects from available processes and allocates CPU cores to maximize utilization and provide fast response times.
Primary Objectives
- Maximize CPU utilization: Keep CPU always busy
- Fast response time: Quick user interaction in time-sharing systems
- Efficient resource usage: Optimal system performance
CPU-I/O Burst Cycle
Process execution consists of alternating sequences:
CPU Scheduler
Selects processes from the ready queue when CPU becomes idle and allocates CPU to chosen process.
Dispatcher
Gives control to the selected process by:
- Performing context switch
- Switching to user mode
- Jumping to correct program location
Dispatch Latency
Time taken to stop one process and start another. Should be minimized as it's pure overhead.
Process Characteristics:
- I/O-bound: Many short CPU bursts
- CPU-bound: Fewer, longer CPU bursts
Preemptive vs Nonpreemptive Scheduling
Nonpreemptive (Cooperative)
Process keeps CPU until it:
- Terminates
- Switches to waiting state
- Voluntarily yields CPU
Preemptive
CPU can be taken away from process:
- Time slice expires
- Higher priority process arrives
- Interrupt occurs
Context Switch
When the CPU switches from one process to another, a context switch occurs.
Context Switch Process:
- Save Context: Store current process state in its PCB
- Select New Process: Scheduler chooses next process
- Load Context: Restore new process state from its PCB
- Resume: Continue execution of new process
Important Notes
- Pure Overhead: No useful work performed during switch
- Speed Critical: Should be minimized
- Hardware Dependent: Speed varies by system
- Memory Impact: May affect cache performance
Scheduling Criteria
| Criterion | Description | Goal |
|---|---|---|
| CPU Utilization | Percentage of time CPU is busy | Maximize (40-90% in real systems) |
| Throughput | Number of processes completed per unit time | Maximize |
| Turnaround Time | Total time from submission to completion | Minimize |
| Waiting Time | Time spent waiting in ready queue | Minimize |
| Response Time | Time from request to first response | Minimize (for interactive systems) |
Session Summary
Key Takeaways:
- Programs are passive entities; processes are active instances in execution
- Processes have five fundamental states: NEW, READY, RUNNING, WAITING, TERMINATED
- PCB contains all information needed to manage a process
- Process scheduling maximizes CPU utilization and provides fast response
- Context switching enables multiprogramming but introduces overhead
- Modern systems use preemptive scheduling for better responsiveness
Process Memory Layout:
- Text Section: Executable code
- Data Section: Global variables
- Heap: Dynamic memory allocation
- Stack: Local variables and function calls
Next Session
Session 2.2: Process Scheduling
CPU-I/O burst cycle, scheduling queues, CPU scheduler and dispatcher, preemptive vs non-preemptive scheduling
Study Tips:
- Draw the process state diagram and practice state transitions
- Understand the difference between programs and processes with examples
- Memorize PCB components and their purposes
- Practice identifying I/O-bound vs CPU-bound processes
- Understand why context switching is considered overhead