0 · Recall Warm-up
Answer from memory first. Answers are in the Answer Vault at the bottom.
- One system call causes how many mode switches? from Lesson 0.1.3
- What does the timer interrupt let the OS do? from Lesson 0.1.2
- Program vs process? from Lesson 0.1.1
1 · The Hook
Open a browser, a music player and a terminal: three processes. Only one can use a single CPU at any instant, so at every moment most of them are waiting for something: the CPU, a key press, a disk read. The OS tracks each one with a record card and moves it between a handful of states. GATE asks which state changes are possible and what the record card holds.
2 · Predict First
Try the questions first. Open when you are ready to check.
A process asks to read a file from disk. Reading takes a long time compared with the CPU. Should the process keep the CPU while it waits?
Make a guess in your head. The answer opens Section 3.
3 · Core Concept
Predict First — the answer
No. It moves to a waiting (blocked) state and the CPU is given to another process. When the disk finishes, the process becomes ready again and waits for its turn on the CPU.
In plain words
A process is a running program with its own memory area. The OS keeps a process control block (PCB), a record card with everything needed to pause and resume it. A process is always in one state: just created, ready to run, running, waiting for something, or finished.
1. A process in memory
| Region | Holds | Grows |
|---|---|---|
| Text (code) | the program's instructions | fixed |
| Data | global and static variables | fixed |
| Heap | memory allocated at run time (malloc, new) | upwards |
| Stack | function calls: local variables, parameters, return addresses | downwards |
2. The process control block (PCB)
One per process, kept by the kernel: process ID (PID), state, program counter (next instruction), CPU registers, scheduling information (priority), memory-management information (page table), list of open files, accounting information. Saving and loading PCBs is how the OS pauses and resumes processes.
3. The five states
| State | Meaning |
|---|---|
| New | being created |
| Ready | could run; waiting only for the CPU |
| Running | instructions are executing on the CPU |
| Waiting (blocked) | waiting for an event: I/O completion, a signal, a resource |
| Terminated | finished |
4. The transitions
| From → To | Cause |
|---|---|
| New → Ready | admitted by the OS |
| Ready → Running | dispatched by the scheduler |
| Running → Ready | pre-empted (timer interrupt, a higher-priority process arrives) |
| Running → Waiting | requests I/O or waits for an event |
| Waiting → Ready | the event happens (I/O finishes) |
| Running → Terminated | exit |
Impossible directly: Waiting → Running (it must go through Ready), Ready → Waiting (it is not running, so it cannot request anything), New → Running.
5. Suspended states
When memory is short, the OS can swap a process out to disk: Ready → Suspended-ready and Waiting → Suspended-waiting (handled by the medium-term scheduler, Lesson 1.1.2). Suspended-waiting becomes Suspended-ready when its event happens; swapping back in returns it to Ready.
4 · Visual
The five-state model. There is no arrow from Waiting straight to Running, nor from Ready to Waiting.
A process's memory (high addresses at the top)
+-----------+
| stack | local variables, return addresses (grows down)
| | |
| v |
| |
| ^ |
| | |
| heap | malloc / new (grows up)
+-----------+
| data | globals, statics
+-----------+
| text | machine code
+-----------+
5 · Worked Examples
Example 1 Easy
A running process's time slice ends. Which state does it move to?
Solution
Ready (pre-empted).
Example 2 Medium
Where does a local variable of a function live: data, heap or stack?
Solution
Stack.
Example 3 GATE
Which transition is NOT possible in the five-state model: Running → Waiting, Waiting → Ready, Waiting → Running, Ready → Running?
Solution
Waiting → Running: a woken process must first become Ready.
6 · GATE Traps
- Waiting → Running directly is impossible; so is Ready → Waiting.
- Pre-emption sends Running → Ready, not Waiting.
- Globals are in data, malloc'd memory in the heap, locals on the stack.
- The PCB is kept by the kernel, not inside the process's own memory.
7 · Memory Hook
"Ready waits for the CPU; Waiting waits for an event."
8 · Connect the Dots
Processes have to come from somewhere. Next lesson creates them with fork(), a GATE favourite for counting questions, and meets the schedulers that move processes between states.
9 · Self-Test
GATE format. Try every question before opening the vault.
Q1 · MCQ · 1 mark(s) — Transitions
Which state transition is impossible?
- (A) Ready → Running
- (B) Waiting → Running
- (C) Running → Waiting
- (D) Running → Ready
Q2 · MCQ · 1 mark(s) — Cause
A process in the Waiting state moves to Ready when:
- (A) the event it was waiting for occurs
- (B) the scheduler dispatches it
- (C) it calls exit
- (D) its time slice ends
Q3 · MSQ · 2 mark(s) — PCB
Which items are stored in a process control block?
- (A) Program counter
- (B) List of open files
- (C) CPU register values
- (D) The source code of the program
Q4 · MCQ · 1 mark(s) — Memory layout
Memory obtained with malloc comes from the:
- (A) data segment
- (B) stack
- (C) text segment
- (D) heap
Q5 · MCQ · 1 mark(s) — Suspension
Memory is short, so the OS swaps a Waiting process out to disk. Its new state is:
- (A) Ready
- (B) Terminated
- (C) Suspended-waiting
- (D) Running
10 · Rule Card
- Process memory: text (code), data (globals), heap (dynamic, grows up), stack (calls, grows down).
- PCB: PID, state, program counter, registers, scheduling info, memory info, open files, accounting.
- States: New, Ready, Running, Waiting, Terminated.
- Transitions: admit, dispatch (Ready→Running), pre-empt (Running→Ready), I/O request (Running→Waiting), event done (Waiting→Ready), exit. Waiting→Running and Ready→Waiting are impossible.
- Suspended-ready / suspended-waiting via swapping.
11 · Concept Ledger
Unlocked in this lesson. From here on, these terms may be used.
processtext, data, heap and stack segmentsprocess control blockprocess IDprogram counterprocess statesdispatchpre-emptionblocking on I/Oimpossible transitionssuspended statesswapping
12 · Answer Vault
Try the questions first. Open when you are ready to check.
🔐 Open the Answer Vault
Recall Warm-up
-
- Take the CPU back from a running process.
- A process is a program in execution.
Self-Test
Q1 Answer: (B) · 1 mark(s)
A woken process goes to Ready first.
- (A) is wrong: Dispatch.
- (C) is wrong: I/O request.
- (D) is wrong: Pre-emption.
Re-read: Lesson 1.1.1 — Processes: memory layout, process control block and process states
Q2 Answer: (A) · 1 mark(s)
I/O completion or a signal.
- (B) is wrong: That moves Ready → Running.
- (C) is wrong: That ends the process.
- (D) is wrong: That moves Running → Ready.
Re-read: Lesson 1.1.1 — Processes: memory layout, process control block and process states
Q3 Answer: (A) (B) (C) · 2 mark(s)
Code is in memory/disk, not the PCB.
- (D) is wrong: Not part of the PCB.
Re-read: Lesson 1.1.1 — Processes: memory layout, process control block and process states
Q4 Answer: (D) · 1 mark(s)
Run-time allocation.
- (A) is wrong: Globals and statics.
- (B) is wrong: Locals and call frames.
- (C) is wrong: Code only.
Re-read: Lesson 1.1.1 — Processes: memory layout, process control block and process states
Q5 Answer: (C) · 1 mark(s)
Swapped out while still waiting for its event.
- (A) is wrong: Its event has not happened.
- (B) is wrong: It has not finished.
- (D) is wrong: It is not on the CPU.
Re-read: Lesson 1.1.1 — Processes: memory layout, process control block and process states