Definition and Overview

Process Concept

Process: instance of a program in execution. Contains program code, current activity, resources. Fundamental OS abstraction for task management.

Role in Operating Systems

OS manages processes to enable multitasking, resource allocation, isolation, and concurrency. Each process has independent execution context.

Distinction from Program

Program: passive code stored on disk. Process: active entity with state, memory, execution flow. Multiple processes can share same program.

Process States

Common States

New: process created, not yet admitted. Ready: prepared for execution, waiting CPU. Running: executing instructions. Waiting: blocked, awaiting event. Terminated: finished execution.

State Transitions

Transition triggered by OS scheduler, I/O events, system calls. Example: Ready → Running on CPU allocation; Running → Waiting on I/O request.

State Diagram

New → Ready → Running → Waiting → Ready → Running → Terminated

Process Control Block (PCB)

Definition

PCB: data structure maintained by OS to store process-specific information. Enables process management, context switching.

PCB Components

Process ID, process state, program counter, CPU registers, memory limits, open files, scheduling info, accounting info, I/O status.

PCB Role in OS

OS uses PCB to track process progress, perform context switches, enforce resource limits, and manage communication.

PCB FieldDescription
Process ID (PID)Unique identifier for the process
Process StateCurrent execution state (Ready, Running, etc.)
Program CounterAddress of next instruction to execute
CPU RegistersValues of CPU registers at process interruption
Memory LimitsBase and limit registers or page tables

Process Scheduling

Purpose

Allocate CPU to processes fairly, efficiently. Maximize CPU utilization, throughput, minimize latency and starvation.

Schedulers

Long-term: admission control. Mid-term: swapping processes. Short-term: selects process for CPU.

Preemptive vs Non-preemptive

Preemptive: OS forcibly switches processes. Non-preemptive: process yields CPU voluntarily.

Context Switching

Definition

Saving state of running process, loading state of next scheduled process. Enables multitasking on single CPU.

Steps Involved

Save CPU registers, program counter, update PCB. Load next process PCB, restore registers, resume execution.

Overhead

Consumes CPU cycles, memory operations. Excessive switching degrades system performance.

ContextSwitch() { Save current_process.PCB; current_process.state = READY; next_process = SchedulerSelect(); Load next_process.PCB; next_process.state = RUNNING; Resume execution;}

Inter-Process Communication (IPC)

Purpose

Processes exchange data, synchronize actions. Essential for cooperative multitasking.

Mechanisms

Shared memory: direct access to common memory region. Message passing: explicit send/receive operations.

Synchronization

Avoid race conditions, ensure data consistency using locks, semaphores, monitors.

IPC MechanismDescriptionUse Case
Shared MemoryProcesses share address space regionHigh-speed data exchange
Message PassingSend/receive messages via kernelDistributed or isolated processes

Threads vs Processes

Process

Heavyweight. Own memory, resources. Isolated address spaces. Context switching cost high.

Thread

Lightweight. Shares process memory, resources. Enables parallel execution within single process.

Comparison

Threads: faster context switching, lower overhead. Processes: better fault isolation, security.

Concurrency and Synchronization

Concurrency

Multiple processes or threads executing overlapping in time. Enables efficient resource use and responsiveness.

Synchronization Primitives

Mutexes, semaphores, condition variables, monitors. Prevent data races, ensure mutual exclusion.

Deadlock Prevention

Avoid circular waits, enforce resource ordering, resource allocation graphs.

SemaphoreWait(S) { while(S <= 0) wait; S = S - 1;}SemaphoreSignal(S) { S = S + 1; wake up waiting process;}

Process Creation and Termination

Creation

System call (fork, spawn). Parent duplicates or creates new process. Allocates PCB, memory, resources.

Termination

Process completes or is killed. OS reclaims resources, updates process tables.

Zombie and Orphan Processes

Zombie: terminated but parent not acknowledged exit. Orphan: parent terminated, adopted by init process.

Multitasking and Multiprogramming

Multiprogramming

Multiple programs loaded in memory. OS switches CPU between them to maximize utilization.

Multitasking

CPU switches rapidly between processes/threads to provide interactive user experience.

Time-sharing

Multitasking variant where CPU time divided into slices (quantum). Ensures fairness and responsiveness.

Scheduling Algorithms

First-Come, First-Served (FCFS)

Simplest. Processes scheduled in arrival order. Drawback: long wait times for short jobs.

Shortest Job Next (SJN)

Schedules shortest process first. Minimizes average waiting time. Requires knowledge of process length.

Round Robin (RR)

Preemptive. Each process receives fixed time quantum. Good for time-sharing systems.

Priority Scheduling

Processes assigned priority. Higher priority runs first. Can cause starvation without aging.

AlgorithmTypeAdvantagesDisadvantages
FCFSNon-preemptiveSimple, easy to implementLong wait times, convoy effect
Round RobinPreemptiveFair, responsiveContext switch overhead
Priority SchedulingPreemptive/Non-preemptivePrioritizes important tasksStarvation risk

Deadlocks and Process Management

Deadlock Definition

Set of processes blocked indefinitely, each waiting for resource held by others.

Necessary Conditions

Mutual exclusion, hold and wait, no preemption, circular wait.

Handling Deadlocks

Prevention, avoidance (Banker’s algorithm), detection and recovery.

DeadlockPrevention() { Ensure at least one condition false: - Disallow mutual exclusion (rare) - Disallow hold and wait: allocate all resources at once - Allow preemption: forcibly reclaim resources - Disallow circular wait: impose resource ordering}

References

  • Silberschatz, A., Galvin, P.B., Gagne, G. Operating System Concepts, 9th Edition, Wiley, 2012, pp. 45-112.
  • Tanenbaum, A.S., Bos, H. Modern Operating Systems, 4th Edition, Pearson, 2015, pp. 123-200.
  • Stallings, W. Operating Systems: Internals and Design Principles, 9th Edition, Pearson, 2018, pp. 230-275.
  • Andrews, G.R. Foundations of Multithreaded, Parallel, and Distributed Programming, Addison-Wesley, 2000, pp. 56-98.
  • Hwang, K., Briggs, F.A. Computer Architecture and Parallel Processing, McGraw-Hill, 1984, pp. 301-350.