Operating System Slides 📂 Introduction · 5 of 22 47 min read

Types of Schedulers & the Process Control Block (PCB)

A visual guide to how the OS decides which process runs next and remembers where each paused one was. Covers the long-, short- and medium-term schedulers, the PCB and its fields, CPU-scheduling algorithms, round-robin, swapping and the context switch — with seven animated diagrams throughout.

🗓️

Types of Schedulers & the Process Control Block

Who decides which process runs next — and how the OS remembers exactly where a paused process was, so it can resume as if it never stopped. The three schedulers and the PCB that ties them together.
3 Schedulers PCB Fields Context Switch task_struct

Press Next → or use ← → arrow keys

Section 01

The Story That Explains Schedulers & PCB

A busy hospital has few doctors, few theatres and limited beds. Three people keep it flowing: reception admits new patients (the long-term scheduler), the triage nurse picks who the doctor sees next (the short-term scheduler), and the ward manager moves stable patients to an overflow ward when beds run out (the medium-term scheduler).

And clipped to the foot of every bed is a patient file — vitals, medicines, assigned doctor. That file is the Process Control Block. Without it, every shift change would be chaos.
💡
Two Questions, One System

Schedulers answer "which process runs next?" The PCB answers "how do we remember exactly where a paused process was?" Together they make multitasking on a single CPU possible.

Section 02 · Recap

Five-State Process Model

admit dispatch I/O wait I/O done interrupt exit NEW READY RUNNING WAITING END P1
🔄
Follow P1 Around the Cycle

Watch process P1 travel the legal path: admitted to Ready, dispatched to Running, bounced back on an interrupt or sent to Waiting for I/O, then back to Ready. Only one process runs per core at any instant.

Section 03

The PCB — What & Why

A Process Control Block (also called a Task Control Block) is a per-process record the kernel keeps, storing everything needed to pause a process now and resume it later exactly where it left off — as if it never stopped.

💾
Context Preservation
Saves the CPU registers, program counter and stack pointer — enabling bit-for-bit resumption.
🪪
Process Identity
Holds PID, PPID and UID — enabling signals, permissions and the process tree from fork().
📇
Resource Tracking
Tracks memory limits, open file descriptors and devices — so the OS can clean up on termination.
🧭
And Scheduling Info

The PCB also stores priority, queue pointers and scheduling policy — the fourth job. It is created when the process is created and destroyed when it terminates: exactly one PCB per process, never before or after.

Section 04 · Anatomy

Inside a PCB — Field by Field

PCB · one block per process, kept in kernel memory Process ID (PID)1247 Process StateREADY Program Counter0x7F3A2C10 CPU RegistersRAX…R15 Scheduling · Priority15 Memory · base+limit0x1000000 Accounting · CPU time2.7 s I/O · open files[0,1,2,7] Parent PID (PPID)1023
🔦
Every Field Earns Its Place

Identity (PID/PPID/UID), the saved CPU context (PC + registers), scheduling data, memory limits, accounting and I/O status. Save all of this and a process can be frozen and thawed perfectly.

Section 06

Three Schedulers, Three Speeds

📥
Long-Term
job scheduler · seconds–minutes
Admits programs from the job pool into the ready queue. Controls the degree of multiprogramming and the CPU/I/O process mix.
Short-Term
CPU scheduler · ~10 ms
Picks which ready process gets the CPU next. Fires constantly, so it must decide in microseconds — its cost is pure overhead.
💾
Medium-Term
swapper · occasional
Swaps processes out to disk under memory pressure and back in later — lowering the degree of multiprogramming when needed.
⏱️
The Frequency Rule

The more often a scheduler runs, the less time it can spend deciding. Long-term is slowest and rarest; short-term is fastest and constant. As frequency goes up, the decision-time budget goes down.

Section 06 · Diagram

Each Scheduler Fires at Its Own Rate

Long-Term every few seconds Medium-Term occasional Short-Term every ~10 ms
🏃
Roughly a 1000:1 Speed Ratio

The long-term orb crawls; the short-term orbs whizz past around a thousand times faster. That gap is why the short-term scheduler must be ruthlessly efficient — it runs while the long-term one has barely moved.

Section 07–08

Long-Term & Short-Term Up Close

A hall has 300 seats (main memory); 800 people wait outside (the job pool). The ticket counter — the long-term scheduler — admits exactly enough to fill the hall. Admit too many and people stand in the aisles (memory overflow); too few and seats sit empty (idle CPU). A good CPU-bound + I/O-bound mix is the single biggest throughput win.
The Short-Term Scheduler's Tight Budget

It runs every time the CPU frees up — a clock interrupt (~10 ms), an I/O wait, or a process exit. If a decision took 10 ms and the OS scheduled every 100 ms, 10% of the CPU would vanish into scheduling. Real kernels decide in microseconds. Also: the scheduler decides who runs; the dispatcher performs the switch — don't confuse them.

Section 08 · Algorithms

Common CPU-Scheduling Algorithms

AlgorithmSelectsPreemptive?Typical use
FCFSOldest process in the queueNoBatch systems
SJFShortest next CPU burstOptionalBatch, theory
PriorityHighest-priority processOptionalReal-time systems
Round RobinNext in queue, time-slice enforcedYesTime-sharing (UNIX, Windows)
Multilevel QueueHighest non-empty queueYesSystems with process classes
⚖️
Preemptive vs Non-Preemptive

Non-preemptive (FCFS, basic SJF) lets a process keep the CPU until it blocks or exits. Preemptive (Round Robin, priority with preemption) can yank the CPU away on a timer or a higher-priority arrival — the basis of responsive time-sharing.

Section 08 · Round Robin

Round-Robin With Three Processes

🧠 CPU Ready Queue P1 P2 P3 dispatch quantum (10 ms) expired → back of queue Timeline P1 P2 P3 0 10 20 30 ms
🎯
Fair Slices, Round and Round

Each process gets a fixed 10 ms quantum on the CPU, then goes to the back of the ready queue while the next one runs. The timeline fills P1, P2, P3, P1… A shorter quantum feels snappier but adds more context-switch overhead — the classic throughput vs latency trade-off.

Section 09

Medium-Term Scheduler — Swap Out & In

MAIN MEMORY (RAM) P1 · running P2 · ready [ free frame ] swap-out → ← swap-in SWAP SPACE (DISK) [ empty slot ] P3 · swapped
📦
Only the Image Leaves — the PCB Stays

Under memory pressure, P3's user-space image slides out to disk and slides back later. Swapping is expensive (milliseconds), so modern systems prefer paging individual pages. Crucially, a swapped-out process keeps its PCB in kernel memory — the PCB is small and precious.

Section 10

All Three Schedulers Working Together

Job Poolon disk READY QUEUE P1 P2 P3 CPURUNNING WAITING (I/O)blocked on a device SUSPENDEDswapped to disk long-term short-term I/O I/O done medium-term
🔧
One Continuous Flow

The long-term scheduler feeds the ready queue, the short-term scheduler dispatches to the CPU, I/O sends a process to Waiting and back, and the medium-term scheduler swaps processes to disk and back. The pipeline never stops.

Section 11

The Three Schedulers Compared

PropertyLong-TermShort-TermMedium-Term
Also calledJob SchedulerCPU Scheduler / DispatcherSwapper
SpeedSlowestFastestMedium
FrequencySeconds–minutesMillisecondsOccasional
TransitionNEW → READYREADY → RUNNINGREADY ↔ SUSPENDED
Controls multiprogrammingYesNoYes
In time-sharing OS?RarelyAlwaysSometimes
GoalGood process mixMax CPU use, low latencyRelieve memory pressure
Section 12

Context Switching With the PCB

PCB(P1) state: RUNNING→READY PC: 0x4021A0 RAX: 0x00A9F3 CPU REGISTERS PC: 0x4021A0 → 0x40332C RAX: 0x00A9F3 → 0x0F1A22 PCB(P2) state: READY→RUNNING PC: 0x40332C RAX: 0x0F1A22 SAVE ↓ LOAD ↑
💃 The save & restore dance · pure overhead (1–10 µs)
1
P1 is running normally on the CPU.
2
Interrupt! Save P1's CPU state (PC, registers, flags) into PCB(P1); mark it READY.
3
Load PCB(P2)'s state into the CPU; mark P2 RUNNING.
4
P2 continues from the exact instruction where it paused.
Section 14

The Textbook Is the Real Thing — task_struct

Linux's PCB is a kernel struct called task_struct. The Galvin fields map almost one-to-one onto it — the textbook is not academic fluff, it's what real kernels implement.

Galvin PCB fieldLinux task_structNotes
PIDpid, tgidProcess & thread-group id
StatestateTASK_RUNNING, TASK_INTERRUPTIBLE…
CPU contextthread_structSaved registers & PC
Memory infomm_struct *mmAddress space, page tables
Open filesfiles_struct *filesFile-descriptor table
Priorityprio, seCFS scheduling entity
Accountingutime, stimeUser/system CPU time
🔎
See It Live

ps -o pid,ppid,stat,pri,etime,comm reads these fields for every process, and cat /proc/<pid>/status dumps a live snapshot of one task's task_struct.

Section 15

Seven Ideas Worth Remembering

🗓️ SCHEDULERS & THE PCB
1
One PCB per process — created at creation, destroyed at termination, never before or after.
2
The short-term scheduler must be fast — every microsecond spent scheduling is stolen from user work. Keep it O(1) or O(log n).
3
The long-term scheduler controls the degree of multiprogramming — too high thrashes, too low idles the CPU. A good CPU/I/O mix beats raw quantity.
4
Context switching is pure overhead — zero user work, 1–10 µs each. Measure it, minimise it, accept it as the cost of multitasking.
5
Modern time-sharing OSes skip the long-term scheduler — Linux, Windows and macOS admit every process at once and lean on paging plus the short-term scheduler.
6
A swapped-out process keeps its PCB in the kernel — only the user-space image goes to disk.
7
Never confuse scheduler and dispatcher — the scheduler decides who runs next; the dispatcher performs the context switch and hands over the CPU.
FINAL

Deciders and the Memory That Serves Them

3Schedulers
9PCB fields
~10msShort-term interval
1000:1Speed ratio
1–10µsContext switch cost
1PCB per process
🎯
You Can Now Explain the Whole Machine's Rhythm

The three schedulers decide which process runs and when; the PCB remembers exactly where each one paused. Together — with the dispatcher performing each context switch — they turn one CPU into the illusion of many.

📚
Where To Go Next

Study the CPU-scheduling algorithms in depth — FCFS, SJF, priority, Round Robin, and multilevel-feedback queues — with their turnaround, waiting and response-time metrics. Then explore process synchronisation and semaphores.

🗓️ End of tutorial · Press to review, or click Restart