4.2.4Operating Systems

Processes — PCB, states (new - ready - running - blocked - terminated)

2,064 words9 min readdifficulty · medium

WHY do processes and states even exist?

WHAT goes wrong without this? If you switched away from a task without saving its CPU registers and program counter, resuming it would be like waking from a coma with amnesia — it wouldn't know which instruction was next. The PCB is the task's "memory card".


The PCB (Process Control Block)

WHAT's inside? (Derive it by asking: "to resume a process perfectly, what must I remember?")

What I must remember PCB field WHY
Which instruction is next Program Counter (PC) so it resumes at the right line
Working values CPU registers mid-calculation data must survive
Current situation Process State ready? blocked? running?
Who is this PID (Process ID) unique identity
Memory layout base/limit, page table so its address space is restored
Open files, devices I/O status info resume file positions, locks
Priority, CPU time used scheduling info for fair scheduling
Accounting CPU usage, limits billing/limits

The Process States

Figure — Processes — PCB, states (new - ready - running - blocked - terminated)

Read each transition as a sentence:

  • admit: OS decides there's room → process joins the ready queue.
  • dispatch: the scheduler picks a ready process and gives it the CPU.
  • timeout/preempt: the time-slice ended (or a higher-priority process arrived) → back to Ready, not Blocked, because it could still run.
  • I/O wait: the process asked for slow data → it gives up the CPU voluntarily and waits.
  • event done: the I/O finished → it goes to Ready (NOT straight to Running — it must re-queue for the CPU).
  • exit: done or killed.

HOW a context switch uses the PCB


Worked examples


Recall Feynman: explain to a 12-year-old

Imagine one TV (the CPU) and many kids who each want to watch their own show (processes). Only one kid watches at a time. When it's the next kid's turn, you write down on a sticky note exactly where the current kid's show was paused, the snacks they had, everything (that's the PCB). Then you swap. A kid can be: just arrived (New), waiting in line (Ready), watching now (Running), gone to the bathroom and can't watch till they're back (Blocked), or finished and left (Terminated). When the bathroom kid comes back, they don't grab the TV instantly — they rejoin the line (Ready), because someone else might be watching!


Active Recall

What is a process?
A program in execution — the live activity with its own memory, registers, and PCB (not just code on disk).
What is the PCB?
Process Control Block — a per-process kernel data structure holding all info (PC, registers, state, PID, memory map, I/O, scheduling) needed to pause and resume the process.
Name the five process states.
New, Ready, Running, Blocked (Waiting), Terminated.
Which state means "has everything except the CPU"?
Ready.
Which state means "waiting on an external event like I/O"?
Blocked / Waiting.
When I/O completes, a process goes from Blocked to ___ (not Running).
Ready.
What transition happens on a time-slice timeout?
Running → Ready (preempt), NOT Running → Blocked.
Why doesn't Blocked go straight to Running?
The CPU may be busy; the scheduler must re-select the process, so it must enter Ready first.
What single PCB field is most critical for correct resumption, and why?
The Program Counter — without it, the CPU wouldn't know the next instruction to execute.
What does a context switch do with PCBs?
Saves outgoing process's registers/PC into its PCB, then loads incoming process's registers/PC from its PCB.
Does the PCB store the program's code?
No — code lives in the process's memory image; the PCB stores metadata + pointers.
What does the dispatcher/scheduler do?
Selects a Ready process and gives it the CPU (Ready → Running).

Connections

  • Context Switching — the mechanism that saves/restores PCBs.
  • CPU Scheduling — decides Ready → Running selection.
  • Threads vs Processes — threads share an address space; lighter than processes.
  • Inter-Process Communication — how separate processes talk.
  • Ready Queue and I-O Queues — where Ready/Blocked processes physically wait.
  • Program vs Process — static code vs dynamic execution.
  • Interrupts — trigger Running → Ready/Blocked transitions.

Concept Map

one at a time forces switching

tracked by

stores PC, registers, state, PID

saves context to

admit

dispatch

timeout or preempt

wait for I/O event

event completes

exit

Process - program in execution

PCB Process Control Block

Single CPU core

Process states

New

Ready

Running

Blocked

Terminated

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, process ka matlab hai ek program jo abhi chal raha hai — sirf disk par pada hua code nahi, balki uska live roop jiske paas apni memory, registers aur ek bookkeeping record hota hai. Yeh record hi PCB (Process Control Block) kehlata hai. Ek CPU core ek time pe sirf ek hi process ko sach me chala sakta hai, isliye OS ko bahut tezi se ek process se doosre process pe switch karna padta hai. Switch karte waqt jis process ko rok rahe hain, uska sab kuch (Program Counter, registers, state) PCB me save karna padta hai, taaki baad me wahi se resume ho — exactly jahan chhoda tha.

Har process kisi na kisi state me hota hai: New (ban raha hai), Ready (sab kuch ready hai, bas CPU ka wait), Running (abhi CPU pe chal raha hai), Blocked (kisi event ka, jaise I/O ka, intezaar kar raha hai), aur Terminated (khatam). Sabse important rule: jab I/O complete ho jaaye, process Blocked se seedha Running nahi jaata — woh pehle Ready me jaata hai, kyunki CPU shayad kisi aur ke paas busy ho, aur scheduler ko phir se use chunna padega.

Ek aur common confusion: timeout (time-slice khatam) hone par process Ready me jaata hai, Blocked me nahi — kyunki woh abhi bhi chal sakta tha, bas turn chala gaya. Blocked sirf tab hota hai jab process kisi external event ka wait kar raha ho. Yeh sab samajhna isliye zaroori hai kyunki yahi se scheduling, context switching aur multitasking ka pura concept khulta hai — interview aur exam dono me yeh state diagram pakka aata hai.

Go deeper — visual, from zero

Test yourself — Operating Systems

Connections