←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
Diagrams

Diagrams

Visual representations for Unit 2

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

Figure 2.1: Memory Layout of a Process Inside Main Memory (RAM)
High Addr1. Stack Section (Grows Downward ↓)
Stores temporary data: function parameters, return addresses & local variables
Dynamic2. Heap Section (Grows Upward ↑)
Memory dynamically allocated at runtime using malloc() or new
Static3. Data Section
Stores Global variables and Static variables
Low Addr4. Text (Code) Section
Contains the actual compiled executable machine code instructions
Explanation
  • Code and static data have roles distinct from the heap and call stack.
  • This logical layout helps explain where instructions, dynamic objects and call frames belong.
Detailed Notes →Quick Revision →

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

Figure 2.2: The 5-State Process Transition Diagram in Operating Systems
1. NEWProcess is being created
→ Admitted →
2. READYIn RAM waiting for CPU
→ Scheduler Dispatch →
3. RUNNINGInstructions executing on CPU
→ Exit →
5. TERMINATEDFinished execution
Explanation
  • A ready process can run once dispatched and blocks when it must wait for an event.
  • Completion of that event returns it to ready before it can run again.
Detailed Notes →Quick Revision →

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

Figure 2.3: Structure and Fields of a Process Control Block (PCB)
Field 1Process ID (PID)
Unique integer identification number assigned to the process (e.g., PID = 1042)
Field 2Process State
Current state: New, Ready, Running, Waiting, or Terminated
Field 3Program Counter (PC)
Holds the memory address of the NEXT instruction to be executed
Field 4CPU Registers
Saved values of Accumulator, Index Registers, Stack Pointers (for Context Switch)
Field 5CPU Scheduling Info
Process Priority number, pointers to scheduling queues
Field 6Memory Management Info
Base & Limit register values, Page Table or Segment Table pointers
Field 7I/O Status & Accounting Info
List of open files, allocated I/O devices, and total CPU time used
Explanation
  • The PCB stores the process identity, state and saved CPU context.
  • Scheduling, memory and resource information help the OS resume and manage the process.
Detailed Notes →Quick Revision →

Figure 2.4: The 3 Types of OS Schedulers

Figure 2.4: The 3 Types of OS Schedulers
1. Long-Term Scheduler (Job Scheduler)
Moves processes from Disk (Job Queue) → RAM (Ready Queue). Controls Degree of Multiprogramming.
2. Short-Term Scheduler (CPU Scheduler)
Picks a process from Ready Queue (RAM) → Allocates CPU. Runs every few milliseconds!
3. Medium-Term Scheduler (Swapper)
Temporarily swaps processes out of RAM to Disk (and back in) to free up memory.
Explanation
  • The long-term scheduler admits jobs and the short-term scheduler selects a ready process.
  • A medium-term scheduler can suspend and later restore a process.
Detailed Notes →Quick Revision →

Figure 2.5: Preemptive Scheduling vs Non-Preemptive Scheduling

Figure 2.5: Preemptive Scheduling vs Non-Preemptive Scheduling
1. Non-Preemptive Scheduling
  • Once the CPU is given to a process, it CANNOT be taken away forcibly!
  • The process keeps the CPU until it finishes its CPU burst or voluntarily waits for I/O
  • Algorithms: FCFS, Non-Preemptive SJF, Non-Preemptive Priority
2. Preemptive Scheduling
  • The OS CAN forcibly interrupt (preempt) a currently running process in the middle of execution!
  • Happens when a higher-priority/shorter job arrives or when the Time Quantum expires
  • Algorithms: SRTN, Round Robin (RR), Preemptive Priority
Explanation
  • A preemptive scheduler can interrupt a running job to serve another.
  • A non-preemptive scheduler waits until the job blocks, yields or ends.
Detailed Notes →Quick Revision →

Figure 2.6: The 5 Core CPU Scheduling Algorithms

Figure 2.6: The 5 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)
Explanation
  • FCFS uses arrival order and shortest-job policies favour short work.
  • Priority uses a rank, while round robin rotates the CPU after a time slice.
Detailed Notes →Quick Revision →

First come, first served CPU timeline

First come, first served CPU timeline
P1 (0–24) ms
P2 (24–27) ms
P3 (27–30) ms
Explanation
  • P1 arrives first in the queue and occupies the CPU for 24 ms.
  • P2 and P3 have short bursts but must wait behind it.
Detailed Notes →Quick Revision →

Shortest job first CPU timeline

Shortest job first CPU timeline
P2 (0–3) ms
P3 (3–6) ms
P1 (6–30) ms
Explanation
  • The two three-millisecond jobs run before the long job.
  • P1 waits six milliseconds while P2 and P3 finish.
Detailed Notes →Quick Revision →

Shortest remaining time CPU timeline

Shortest remaining time CPU timeline
P1 (0–1) ms
P2 (1–5) ms
P4 (5–10) ms
P1 (10–17) ms
P3 (17–26) ms
Explanation
  • P2 displaces P1 when it arrives with a shorter remaining time.
  • At each completion the scheduler again chooses the shortest unfinished job that has arrived.
Detailed Notes →Quick Revision →

Round robin CPU timeline

Round robin CPU timeline
P1 (0–4) ms
P2 (4–8) ms
P3 (8–12) ms
P1 (12–16) ms
P3 (16–17) ms
P1 (17–19) ms
Explanation
  • A running job gets up to four milliseconds before returning to the ready queue.
  • Finished jobs leave the rotation, so the last two slices can be shorter.
Detailed Notes →Quick Revision →

Figure 2.7: Two Classical Hard Real-Time Scheduling Algorithms

Figure 2.7: Two Classical Hard Real-Time Scheduling Algorithms
1. Rate-Monotonic (RM) Scheduling
  • Static Priority algorithm for periodic tasks
  • Priority is assigned based on the inverse of the task's period ((1 / P))
  • Shorter period (runs more frequently) = Higher Priority!
2. Earliest-Deadline-First (EDF)
  • Dynamic Priority algorithm
  • Whenever a task needs the CPU, the scheduler picks the task whose deadline is closest!
  • Earlier deadline = Higher Priority (Optimal, up to 100% CPU utilization)
Explanation
  • Rate-monotonic scheduling gives shorter-period tasks higher fixed priority.
  • Earliest-deadline-first changes priority according to the nearest deadline.
Detailed Notes →Quick Revision →

Figure 2.8: Multilevel Queue (MLQ) Scheduling Architecture

Figure 2.8: Multilevel Queue (MLQ) Scheduling Architecture
Priority 1 (Highest)System Processes Queue
Kernel & OS tasks — Scheduled using Priority / RR
Priority 2Interactive Processes (Foreground)
GUI & User apps — Scheduled using Round Robin (RR)
Priority 3Interactive Editing Processes
Text editors & IDEs — Scheduled using RR / SJF
Priority 4 (Lowest)Batch Processes (Background)
Backups & Long jobs — Scheduled using FCFS
Explanation
  • A multilevel queue places jobs in classes with their own scheduling rules.
  • A separate rule decides which queue gets the processor.
Detailed Notes →Quick Revision →

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

Figure 2.9: Multilevel Feedback Queue (MLFQ) — Processes Move Between Queues
Queue 0 (Highest Priority)Round Robin (Quantum = 8 ms)
→ If not finished in 8 ms, Demote ↓ →
Queue 1 (Medium Priority)Round Robin (Quantum = 16 ms)
→ If not finished in 16 ms, Demote ↓ →
Queue 2 (Lowest Priority)FCFS (Runs when Q0 & Q1 are empty)
Explanation
  • Feedback allows a process to move between priority queues as it runs or waits.
  • Its recent behaviour can therefore affect the next time it receives CPU service.
Detailed Notes →Quick Revision →