4.2.4 · HinglishOperating Systems

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

1,929 words9 min readRead in English

4.2.4 · Coding › Operating Systems


WHY do processes and states even exist?

WHAT goes wrong without this? Agar tum kisi task se bina uske CPU registers aur program counter save kiye switch kar lo, toh resume karna aisa hoga jaise coma se uthne ke baad amnesia ho — use pata nahi hoga ki agla instruction kaun sa tha. PCB task ka "memory card" hai.


The PCB (Process Control Block)

WHAT's inside? (Isko derive karo yeh poochh ke: "ek process ko perfectly resume karne ke liye mujhe kya yaad rakhna chahiye?")

Mujhe kya yaad rakhna hai PCB field WHY
Agla instruction kaun sa hai Program Counter (PC) taaki woh sahi line pe resume ho
Working values CPU registers calculation ke beech ka data bachna chahiye
Current situation Process State ready? blocked? running?
Yeh kaun hai PID (Process ID) unique identity
Memory layout base/limit, page table taaki uska address space restore ho
Open files, devices I/O status info file positions, locks resume karne ke liye
Priority, CPU time used scheduling info fair scheduling ke liye
Accounting CPU usage, limits billing/limits

The Process States

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

Har transition ko ek sentence ki tarah padho:

  • admit: OS decide karta hai ki jagah hai → process ready queue mein join karta hai.
  • dispatch: scheduler ek ready process choose karta hai aur use CPU deta hai.
  • timeout/preempt: time-slice khatam ho gaya (ya koi higher-priority process aa gaya) → Ready mein wapas, Blocked mein nahi, kyunki woh run kar sakta hai.
  • I/O wait: process ne slow data maanga → CPU voluntarily chhodta hai aur wait karta hai.
  • event done: I/O khatam hua → Ready mein jaata hai (seedha Running mein NAHI — use CPU ke liye phir se queue karna padta hai).
  • exit: kaam khatam ya kill ho gaya.

HOW a context switch PCB use karta hai


Worked examples


Recall Feynman: 12-saal ke bachche ko samjhao

Socho ek TV hai (CPU) aur kaafi saare bachche hain jo apna-apna show dekhna chahte hain (processes). Ek waqt mein sirf ek bachcha dekhta hai. Jab agla bachche ki baari aati hai, tum ek sticky note pe likh dete ho ki current bachche ka show exactly kahan pause hua tha, unke paas kya snacks the, sab kuch (yeh PCB hai). Phir swap karo. Ek bachcha ho sakta hai: abhi abhi aaya (New), line mein wait kar raha (Ready), abhi dekh raha (Running), bathroom gaya hai aur wapas aane tak nahi dekh sakta (Blocked), ya khatam karke chala gaya (Terminated). Jab bathroom wala bachcha wapas aata hai, woh TV turant nahi uthaa leta — woh line mein wapas aata hai (Ready), kyunki shayad koi aur dekh raha ho!


Active Recall

Process kya hai?
Ek program in execution — woh live activity jiske paas apni memory, registers, aur PCB hoti hai (sirf disk pe pada code nahi).
PCB kya hai?
Process Control Block — ek per-process kernel data structure jo process ko pause aur resume karne ke liye zaroori saari info (PC, registers, state, PID, memory map, I/O, scheduling) rakhta hai.
Paanch process states batao.
New, Ready, Running, Blocked (Waiting), Terminated.
Kaun si state ka matlab hai "CPU ke alawa sab kuch hai"?
Ready.
Kaun si state ka matlab hai "I/O jaisa baahri event ka wait kar raha hai"?
Blocked / Waiting.
Jab I/O complete hota hai, ek process Blocked se ___ mein jaata hai (Running nahi).
Ready.
Time-slice timeout pe kaun sa transition hota hai?
Running → Ready (preempt), Running → Blocked NAHI.
Blocked seedha Running mein kyun nahi jaata?
CPU busy ho sakta hai; scheduler ko process ko dobara select karna padta hai, isliye pehle Ready mein aana hota hai.
Sahi resumption ke liye sabse critical PCB field kaun si hai, aur kyun?
Program Counter — iske bina CPU ko pata nahi chalega ki agla instruction kaun sa execute karna hai.
Context switch PCBs ke saath kya karta hai?
Jaane wale process ke registers/PC uske PCB mein save karta hai, phir aane wale process ke registers/PC uske PCB se load karta hai.
Kya PCB program ka code store karta hai?
Nahi — code process ki memory image mein rehta hai; PCB metadata + pointers store karta hai.
Dispatcher/scheduler kya karta hai?
Ek Ready process select karta hai aur use CPU deta hai (Ready → Running).

Connections

  • Context Switching — woh mechanism jo PCBs save/restore karta hai.
  • CPU Scheduling — Ready → Running selection decide karta hai.
  • Threads vs Processes — threads ek address space share karte hain; processes se lighter hote hain.
  • Inter-Process Communication — alag processes aapas mein kaise baat karte hain.
  • Ready Queue and I-O Queues — jahan Ready/Blocked processes physically wait karte hain.
  • Program vs Process — static code vs dynamic execution.
  • Interrupts — Running → Ready/Blocked transitions trigger karte hain.

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