←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Revision

Operating System · Unit 2 Revision

Quick summary and key points for Unit 2

Process Management: Process Concepts, Process States & Process Control Block (PCB)

Overview: A student program waiting for keyboard input is blocked.

Process Concepts: What is a Process?

  • A Process is formally defined as “a program in execution”.
  • When a software program (like chrome.exe or vlc.exe) sits on your hard disk, it is just a passive file of binary instructions called a…
  • The moment you double-click that file, the Operating System loads it into Main Memory (RAM), allocates CPU registers and resources to…
  • 1. Nature: A Passive (Static) entity stored on disk containing a set of instructions.
  • 2. Storage Location: Stored on Secondary Storage (Hard Disk / SSD) as an .exe file.
  • 3. Lifespan: Permanent (exists on disk until deleted by the user).
  • 4. Resource Requirement: Requires only disk space to store the file.
  • Memory Layout of a Process in RAM: When the OS loads a program into RAM to create a process, its memory space is divided into 4 sections:

View diagram · Figure 2.1: Memory Layout of a Process Inside Main Memory (RAM)

Process States (The 5-State Process Lifecycle)

  • As a process executes, it changes its State depending on what it is currently doing.
  • Detailed Explanation of the 5 Process States: New State:
  • Ready State:
  • Running State:
  • Waiting (or Blocked) State:
  • Terminated (Exit) State:

View diagram · Figure 2.2: The 5-State Process Transition Diagram in Operating Systems

Process Control Block (PCB) / Task Control Block

  • How does the Operating System keep track of 100 different processes running at the same time?
  • Process ID (PID) Unique integer identification number assigned to the process (e.g., PID = 1042)
  • Process State Current state: New, Ready, Running, Waiting, or Terminated
  • Program Counter (PC) Holds the memory address of the NEXT instruction to be executed
  • CPU Registers Saved values of Accumulator, Index Registers, Stack Pointers (for Context Switch)
  • CPU Scheduling Info Process Priority number, pointers to scheduling queues
  • Memory Management Info Base & Limit register values, Page Table or Segment Table pointers
  • I/O Status & Accounting Info List of open files, allocated I/O devices, and total CPU time used

View diagram · Figure 2.3: Structure and Fields of a Process Control Block (PCB)

Context Switching & Threads Overview

  • A. What is Context Switching?: When the CPU switches from executing Process P1 to executing Process P2, the OS must:
  • Save the current state (Program Counter & CPU Registers) of Process P1 into P1’s PCB.
  • Load (restore) the saved state of Process P2 from P2’s PCB into the CPU registers.
  • B. Threads (Lightweight Processes): A Thread is a lightweight sub-process and the basic unit of CPU utilization within a process.
  • Each thread has its own Thread ID, Program Counter, Register Set, and Stack, but shares the **Code Section, Data Section, and OS…

Process Scheduling: Queues, Schedulers, Preemptive vs Non-Preemptive & Criteria

Overview: Turnaround time runs from arrival to completion.

What is Process Scheduling?

  • In a multiprogramming or time-sharing system, dozens of processes compete for the CPU at the same time.
  • The 3 Process Scheduling Queues: As processes enter the system and change states, the OS places their PCBs into three main queues:
  • Job Queue: Holds all processes in the system that have arrived and are waiting on the hard disk to be brought into main memory…
  • Ready Queue: Holds all processes that are residing in Main Memory (RAM) and are ready and waiting to execute on the CPU.
  • Device (Waiting) Queues: Holds processes that are currently blocked waiting for a specific I/O device (e.g., Disk Queue, Printer Queue).

Types of Schedulers (Long-Term, Short-Term & Medium-Term)

  • The OS uses three types of schedulers to move processes between these queues:
  • 1. Long-Term Scheduler (Job Scheduler) Moves processes from Disk (Job Queue) → RAM (Ready Queue).
  • 2. Short-Term Scheduler (CPU Scheduler) Picks a process from Ready Queue (RAM) → Allocates CPU.
  • 3. Medium-Term Scheduler (Swapper) Temporarily swaps processes out of RAM to Disk (and back in) to free up memory.
  • 1. Also Called: Job Scheduler
  • 2. What It Does: Selects jobs from Disk (Job Queue) and loads them into RAM (Ready Queue).
  • 3. Execution Speed: Executes infrequently (once every few seconds or minutes).
  • 4. Effect on Degree of Multiprogramming: Controls (Increases) the Degree of Multiprogramming (number of processes in RAM).

View diagram · Figure 2.4: The 3 Types of OS Schedulers

Preemptive vs Non-Preemptive Scheduling

  • Every CPU scheduling algorithm falls into one of two categories depending on whether the OS can forcibly take the CPU away from a running…
  • 1. Basic Rule: The CPU can be taken away from a running process before it finishes.
  • 2. Response Time: Very Fast / Low Response Time (short/urgent tasks don’t get stuck behind long jobs).
  • 3. Context Switch Overhead: High overhead due to frequent context switching.
  • 4. Synchronization Needed?: Yes (shared data can be corrupted if preempted mid-update).
  • 5. Examples: Round Robin (RR), SRTN (Preemptive SJF), Preemptive Priority.

View diagram · Figure 2.5: Preemptive Scheduling vs Non-Preemptive Scheduling

CPU Scheduling Criteria (Performance Metrics)

  • How do we compare different scheduling algorithms (FCFS, SJF, Round Robin) and decide which one is best?
  • 1. CPU Utilization (Maximize ↑): Definition: The percentage of time that the CPU remains actively busy executing processes (ideally between 40% on a lightly loaded…
  • Goal: Maximize CPU Utilization.
  • 2. Throughput (Maximize ↑): Definition: The total number of processes completed per unit of time (e.g., 15 processes per second).
  • Goal: Maximize Throughput.
  • 3. Turnaround Time — TAT (Minimize ↓): Definition: The **total time interval from the moment a process arrives (is submitted) until the moment it completely finishes…
  • Formula: Turnaround Time (TAT) = Completion Time (CT) - Arrival Time (AT)
  • Goal: Minimize Turnaround Time.

CPU Scheduling Algorithms: FCFS, SJF, SRTN, Round Robin & Priority

Overview: Suppose two jobs arrive together and need five and one CPU units.

Overview of Classical CPU Scheduling Algorithms

  • In DAVV BCA exams, Unit 2 always includes an 8-mark theory + Gantt chart numerical question on these five core CPU scheduling algorithms:
  • 1. FCFS First-Come, First-Served (Non-Preemptive FIFO Queue)
  • 2. SJF Shortest Job First (Non-Preemptive — Picks smallest Burst Time)
  • 3. SRTN / SRTF Shortest Remaining Time Next (Preemptive version of SJF)
  • 4. Round Robin (RR) Preemptive Time-Sharing using a fixed Time Quantum (q)
  • 5. Priority Scheduling Picks process with highest Priority number (Preemptive or Non-Preemptive)

View diagram · Figure 2.6: The 5 Core CPU Scheduling Algorithms

First-Come, First-Served (FCFS) Scheduling

  • Mode: Strictly Non-Preemptive.
  • How It Works: The simplest scheduling algorithm.
  • Major Drawback — The Convoy Effect:
  • Solved Numerical Example (FCFS): Suppose 3 processes arrive at time AT = 0 in the order P1, P2, P3:
  • P1: 0
  • P2: 0
  • P3: 0
  • Average Waiting Time: (0 + 24 + 27) / 3 = 17.0 ms

View diagram · First come, first served CPU timeline

Shortest Job First (SJF — Non-Preemptive)

  • Mode: Non-Preemptive.
  • How It Works: Among all available processes in the Ready Queue, the CPU is assigned to the process that has the **smallest (shortest) next…
  • Key Advantage: SJF is mathematically proven to be Optimal—it gives the minimum possible Average Waiting Time for a given set of…
  • Disadvantage: In practice, it is difficult to know the exact future CPU burst length of a process in advance, and long processes may…
  • Solved Numerical Example (Non-Preemptive SJF): Using the exact same 3 processes (P1 = 24 ms, P2 = 3 ms, P3 = 3 ms) arriving at AT = 0, SJF runs the shortest jobs (P2, P3)…
  • Waiting Times: P2 = 0 ms, P3 = 3 ms, P1 = 6 ms.
  • Average Waiting Time: (0 + 3 + 6) / 3 = 3.0 ms (Dropped from 17 ms in FCFS down to just 3 ms!)

View diagram · Shortest job first CPU timeline

Shortest Remaining Time Next (SRTN / SRTF)

  • Mode: Preemptive version of SJF!
  • How It Works: At any moment, the CPU executes the process with the shortest remaining burst time.
  • Whenever a new process arrives in the Ready Queue, the scheduler compares its Burst Time with the remaining time of the currently…
  • P1: 0
  • P2: 1
  • P3: 2
  • P4: 3
  • Solved Numerical Example (SRTN): Step-by-Step Execution & Gantt Chart:

View diagram · Shortest remaining time CPU timeline

Round Robin (RR) Scheduling

  • Mode: Preemptive (Designed specifically for Time-Sharing Systems).
  • How It Works:
  • A small fixed unit of time called a Time Quantum (q) or Time Slice (typically 10 ms to 100 ms) is defined.
  • The Ready Queue is treated as a circular FIFO queue.
  • The scheduler gives the first process in the queue the CPU for at most 1 Time Quantum.
  • Effect of Time Quantum Size:
  • If Time Quantum is too large (∞): Round Robin degenerates into simple FCFS.
  • If Time Quantum is too small (1 ms): Causes excessive Context Switch Overhead, slowing down the CPU.

View diagram · Round robin CPU timeline

Priority Scheduling (Starvation & Aging)

  • Mode: Can be either Preemptive or Non-Preemptive.
  • How It Works: A Priority Number (an integer) is associated with each process, and the CPU is allocated to the process with the…
  • Major Problem — Starvation (Indefinite Blocking):
  • The Solution — Aging:

Multiple-Processor, Real-Time, Multilevel Queue & Multilevel Feedback Queue Scheduling

Overview: Two CPU cores may run two ready jobs at once.

Multiple-Processor Scheduling

  • When a computer system has multiple CPUs (or a Multi-Core Processor), scheduling becomes more complex because multiple processes can run in…
  • Two Approaches to Multiple-Processor Scheduling: Asymmetric Multiprocessing (AMP):
  • Symmetric Multiprocessing (SMP — Standard Today):
  • Two Key Issues in SMP Scheduling: Processor Affinity: When a process runs on CPU Core 1, its data fills up Core 1’s high-speed Cache Memory.
  • Load Balancing: Ensures that one CPU core isn’t sitting idle while another core has 10 processes waiting in its queue.

Real-Time CPU Scheduling

  • In Real-Time Operating Systems (RTOS), processes have strict Deadlines by which they must complete:
  • Soft Real-Time Scheduling: Guarantees that critical real-time processes are given higher priority than non-critical processes, though it does not…
  • Hard Real-Time Scheduling: A process must be serviced before its deadline expires; once admitted, the OS guarantees on-time completion using two famous…
  • 1. Rate-Monotonic (RM) Scheduling Static Priority algorithm for periodic tasks
  • 2. Earliest-Deadline-First (EDF) Dynamic Priority algorithm

View diagram · Figure 2.7: Two Classical Hard Real-Time Scheduling Algorithms

Multilevel Queue (MLQ) Scheduling

  • In real operating systems, all processes are not alike!
  • How Multilevel Queue (MLQ) Scheduling Works: The Ready Queue is partitioned into several separate, permanent queues based on the type/priority of processes.
  • A process is permanently assigned to one queue when it enters the system (based on process type, memory size, or priority) and **CANNOT…
  • Each queue has its own independent scheduling algorithm (e.g., Interactive queue uses Round Robin, while Batch queue uses FCFS).
  • System Processes Queue Kernel & OS tasks — Scheduled using Priority / RR
  • Interactive Processes (Foreground) GUI & User apps — Scheduled using Round Robin (RR)
  • Interactive Editing Processes Text editors & IDEs — Scheduled using RR / SJF
  • Batch Processes (Background) Backups & Long jobs — Scheduled using FCFS

View diagram · Figure 2.8: Multilevel Queue (MLQ) Scheduling Architecture

Multilevel Feedback Queue (MLFQ) Scheduling

  • Why Was MLFQ Invented?: In standard Multilevel Queue (MLQ) scheduling, processes are permanently locked into one queue (inflexible) and…
  • How Multilevel Feedback Queue (MLFQ) Works: New Process Entry: Every new process enters at the top Queue 0 and is given a short time quantum of 8 ms (Round Robin).
  • If it is a short/interactive I/O process, it finishes within 8 ms and leaves immediately!
  • Demotion (Punishing CPU Hogs): If the process does not finish within 8 ms, it is preempted and moved down (demoted) to Queue 1, where it gets a…
  • If it still does not finish in 16 ms, it is demoted to Queue 2 (FCFS) at the bottom.
  • Promotion (Preventing Starvation via Aging): If a process waits too long in a lower queue (Queue 2) without getting the CPU, the OS **promotes (upgrades) it back…

View diagram · Figure 2.9: Multilevel Feedback Queue (MLFQ) — Processes Move Between Queues

Comparison: Multilevel Queue (MLQ) vs Multilevel Feedback Queue (MLFQ)

  • This is a favorite 5- to 8-mark comparison question in DAVV BCA exams!
  • 1. Process Movement: Processes are permanently assigned to one queue and cannot move between queues.
  • 2. Flexibility: Rigid and Inflexible (requires knowing process nature in advance).
  • 3. Starvation Risk: High risk of Starvation for lower-priority queues under fixed priority.
  • 4. Design Complexity: Simple to implement with low overhead.