Processes, States and Threads
What a process is, the PCB, the five-state model, and how threads share address space.
- Distinguish a program from a process and list PCB contents
- Draw the five-state process model and explain each transition
- Compare process vs thread and name shared vs private resources
Interview opener: "What is the difference between a process and a thread?" If you say "thread is lighter" without naming the shared address space, you lose half the marks. This lesson builds the model examiners actually want.
Program vs process: A program is passive text on disk. A process is a program in execution with its own address space, registers and kernel resources. One program → many concurrent processes.
PCB (Process Control Block): the kernel's identity card for a process — PID, process state, program counter, CPU registers, memory-management info, accounting, I/O status.
Five-state model:
- New — admitted, not yet admitted to ready queue
- Ready — waiting for CPU
- Running — instructions executing on a CPU
- Waiting/Blocked — waiting for I/O or an event
- Terminated — finished; PCB reclaimed
Transitions: admit → ready; dispatch → running; I/O wait → waiting; I/O done → ready; exit → terminated. Preemption: running → ready (time slice over).
Context switch: save state of current process, load state of next. Pure overhead — no useful work. Cost grows with address-space size (more to swap) and with TLB flushes on some architectures.
Threads: a thread is a unit of schedulability inside a process.
- Shared: code, data, heap, open files, signal handlers
- Private: thread ID, program counter, registers, stack, errno
User-level threads are invisible to the kernel (one blocking call blocks all). Kernel-level threads are scheduled independently. Java's default model is 1:1 kernel threads on modern JVMs.
| Meaning / waiting for | |
|---|---|
| New | Created; not in ready queue yet |
| Ready | CPU; only the scheduler decides |
| Running | On a CPU core |
| Waiting | I/O or event; cannot run even if CPU free |
| Terminated | Done; PCB not yet reaped (zombie parent case) |
Any "what does the OS keep about a process" answer starts with PCB fields.
Waiting means no CPU will help until the event completes; ready means a dispatch will.
- 1
New
Job admitted to the system after validation.
- 2
Ready
PCB created; process sits in the ready queue.
- 3
Running
Scheduler dispatches it to a core.
- 4
Waiting
Execute read(fd); blocked until interrupt completes.
- 5
Ready again
I/O interrupt; process requeued.
- 6
Running
Second dispatch; reaches exit.
- 7
Terminated
Exit status stored for the parent wait().
Solution
Full lifecycle; every transition has a reason (admit, dispatch, I/O, interrupt, exit).
List three resources shared by threads of one process and three that stay private to each thread.
Hint: Shared follows the address space; private follows the execution context.
Saying a thread has its own address space
Threads share the process address space; only stacks/registers differ.
Calling context switch free because "the OS does it"
It is pure overhead: save/load + possible TLB shootdown.
PCB vs program?
A program is passive code; a PCB is the runtime record the kernel keeps for each process (PID, state, PC, registers, memory, I/O).
Source: Most repeated OS interview question.
- Process = program in execution; PCB is its kernel identity.
- Five states; waiting is not ready.
- Threads share address space; stacks and registers are private.