Processes, process states and the PCB
Processes, their possible states, state transitions and the Process Control Block (PCB) — what a process is, how an OS tracks it, and how context switching saves and restores a PCB.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Operating systems manage programs while they run. An engineer uses the ideas of process states and the Process Control Block (PCB) whenever designing or debugging OS code (schedulers, context-switch code, device drivers) or when reasoning about multitasking behaviour and performance. Clear understanding helps to implement context switching correctly and to reason about resource usage, deadlocks and scheduling (other topics in the course).
Key ideas
Start with definitions (each bold word is defined before it is used):
- Process — a program in execution; it is an active entity that needs CPU time, memory and I/O to run. A process is not the same as the program text on disk (the static file).
- Process state — the current status of a process describing what it is doing now (for example, using CPU, waiting for I/O). Process states are labels the OS assigns; they are used to control scheduling and resource allocation.
- Process Control Block (PCB) — the kernel data structure that stores all information the OS needs to manage a specific process. Each active process has one PCB.
- Context switch — the operation the OS performs to stop running one process and start running another. It involves saving the outgoing process's context into its PCB and loading the incoming process's context from its PCB.
Standard model (assumptions):
- A single CPU core executes one thread of one process at a time. In modern systems the scheduler typically runs threads (lightweight processes); per-thread contexts are stored in Thread Control Blocks (TCBs), while the PCB holds per-process resources (address space, open files, credentials).
- Processes alternate between CPU bursts and I/O bursts.
- The OS runs in kernel mode and can preempt processes when required (preemptive multitasking). If your OS is non-preemptive, some transitions differ.
Typical process-state model and explanation (exact statement to memorise):
- Common process states: New, Ready, Running, Waiting (or Blocked), Terminated.
- Definition: Ready — the process is in main memory and ready to run when CPU is available. Running — its instructions are executing on the CPU. Waiting — the process suspended execution because it is waiting for an event (I/O completion, signal). New — the process is being created. Terminated — the process has finished execution and is waiting for the OS to remove its PCB and free resources.
State transitions (explicit, step-by-step):
- New → Ready: After creation (fork/exec-like operation), OS sets up PCB and places process in the ready queue.
- Ready → Running: Scheduler selects the process and dispatches it to the CPU.
- Running → Waiting: Process performs an operation that cannot proceed (e.g., requests disk I/O); the OS blocks it and starts I/O; CPU is freed. This is a voluntary relinquish of CPU.
- Running → Ready: Preemption (e.g., time-slice expires or higher-priority process arrives); the OS saves the process context and places it back into the ready queue.
- Waiting → Ready: The event the process waited for occurs (I/O completes); the OS moves it back to ready queue.
- Running → Terminated: Process finishes or is killed; OS frees resources (some resources may be freed later after parent collects status).
Describe the diagram you should draw for exams: draw five circles labelled New, Ready, Running, Waiting, Terminated. Draw arrows: New→Ready, Ready→Running, Running→Waiting, Waiting→Ready, Running→Ready (label this arrow "preempt/time slice"), Running→Terminated. Label each arrow with the event that causes the transition (create, dispatch, I/O request, I/O completion, time slice expire, exit). Some textbooks also show Ready Suspended and Blocked/Waiting Suspended for swapped-out processes; know that these indicate the same states but not resident in main memory.
Process Control Block — exact contents and why each item is required (memorise list and purpose):
- Process identifier (PID): unique number to identify the process.
- Process state: the current state label (Ready/Running/Waiting etc.).
- Program counter (PC): address of next instruction to execute — required to resume process after preemption.
- CPU registers set: general-purpose registers, stack pointer, index registers — saved/restored on context switch to preserve execution state.
- CPU scheduling information: priority, scheduling queue pointers, expected/accumulated CPU burst times — used by scheduler.
- Memory-management information: base and limit registers or page tables or segment tables — needed to give correct address translation when process runs.
- Accounting information: CPU used, clock time used, user and system time, limits — for billing, quotas and statistics.
- I/O status information: list of open file descriptors, I/O devices allocated to process, pending I/O requests — for resource management and I/O completion.
- Parent/child relationship info and process control links: pointers to parent, list of children, and kernel objects used for wait/exit — for process hierarchy and cleanup.
- Credentials and security context: user ID, group IDs, capabilities/privileges — for access control and auditing.
- Signal/exception handlers and masks: registered handlers, pending signals, signal mask — to deliver and control asynchronous events.
Exact steps of a context switch (what the kernel must do; memorise order):
- Save CPU registers and program counter of the outgoing process into its PCB.
- Save other processor state (stack pointer, status registers, floating-point state if used) into PCB.
- Update the outgoing process state to Ready or Waiting (depending on cause).
- Choose the next process to run (scheduler) and remove it from the ready queue.
- Update the incoming process state to Running.
- Switch memory map (load page table base register or segment registers) to the incoming process's memory map.
- Load CPU registers, program counter and other saved processor state from the incoming process's PCB.
- Resume execution at the restored program counter.
Cost and effects: context switch is overhead — it uses CPU cycles without making forward progress on user work. Time spent saving/restoring registers and updating memory maps reduces CPU throughput. Some systems reduce cost by lazy saving/restoring floating-point/SIMD state and by using hardware features (e.g., address-space identifiers/PCID) to avoid full TLB flushes. A mode switch (user↔kernel) without changing the running thread is cheaper than a full context switch.
Formulas
Turnaround time = completion time − arrival time — Turnaround time: time units (seconds or milliseconds). Applies when measuring how long a process takes from arrival to finish.
Waiting time = turnaround time − total CPU burst time — Waiting time: time units. Applies when only CPU service time is counted (no I/O durations). If I/O/service times are included in turnaround, use Waiting time = turnaround time − total CPU burst time − total I/O time (time spent only in the ready queue).
Response time = time of first CPU allocation − arrival time — Response time: time units. Applies in interactive systems where first response matters.
CPU utilization = (time CPU was busy) / (total observed time) — dimensionless (fraction or percentage). Use when analysing overall processor busy fraction.
Throughput = number of processes completed / total observed time — units: processes per second. Applies to measure system output.
Note: All times should be in same unit (seconds or ms). If problem gives ms, keep ms throughout.
Worked examples
Example 1 — Model long-answer: "Explain the process state diagram and the causes of each transition" (model answer for full marks).
Answer: Begin by defining a process and process state. Draw the diagram as described above: five circles (New, Ready, Running, Waiting, Terminated) and labelled arrows New→Ready (create), Ready→Running (dispatch), Running→Waiting (I/O request), Waiting→Ready (I/O completion), Running→Ready (preemption/time-slice), Running→Terminated (exit). Then explain each state:
- New: process being created; OS allocates PCB, address space and descriptors.
- Ready: in memory, waiting for CPU; placed on ready queue.
- Running: instructions executing; has CPU.
- Waiting: cannot continue until event (I/O, child termination, signal) — not on ready queue.
- Terminated: finished; OS keeps PCB until parent reads exit status.
Explain transitions with examples: I/O request: process issues disk read; kernel blocks it and schedules another. Preemption: timer interrupt causes kernel to save context and put process back to ready. Termination: process executes exit system call; kernel frees resources and changes state to terminated. Conclude by discussing how this model supports multiprogramming and mention that the scheduler and context-switch code implement the transitions.
Example 2 — Model long-answer: "Describe the PCB and show step-by-step how a context switch works" (model answer for full marks).
Answer: Define PCB as the per-process kernel data structure. List standard PCB fields (PID, state, PC, registers, memory map info, scheduling info, accounting, I/O info, parent/child links). Explain why each is necessary (PC and registers to resume; memory info to switch page tables; I/O info to route interrupts). Then give exact context switch steps in order (1 to 8) and explain the role of kernel mode, interrupts and the scheduler. Mention the cost: copying registers, TLB flush or page-table base register update, cache effects. Finish with how the PCB enables preemption and process isolation.
Optional short numerical example (if asked): compute turnaround and waiting times for a single process: arrival 0 ms, CPU bursts total 120 ms, completion at 180 ms: Turnaround = 180 − 0 = 180 ms. Waiting = 180 − 120 = 60 ms. Assume no I/O durations are counted; if I/O bursts total X ms, then Waiting = 180 − 120 − X ms. State these with units and mark final answers bold.
Common mistakes
- Mixing up Ready and Waiting states — Ready means waiting for CPU, Waiting means waiting for I/O/event.
- Omitting memory-management info from PCB — address translation must be switched during context switch.
- Describing context switch without mentioning kernel mode/interrupt or scheduler involvement.
For your exam
Kinds of questions: definitions (short), draw and explain the process-state diagram (diagram + explanation), list and explain PCB fields, describe step-by-step context switch, short derivations for time metrics (turnaround, waiting), and long-answer discussion of overheads and effects.
What a full-marks answer includes:
- For definitions: the exact one-line definition and brief explanation.
- For diagram questions: a neatly drawn labelled diagram (New, Ready, Running, Waiting, Terminated) with arrows and event labels, plus short explanation of each state and transition.
- For PCB/context-switch: list of PCB fields with purpose, and step-by-step numbered context switch procedure including when registers, PC and memory map are saved/restored. Mention effects on performance and resource cleanup for Terminated.
Quick check
- What is a process? 2) Name four fields stored in a PCB. 3) What causes a Running → Ready transition?
Answers: 1) A process is a program in execution (an active entity). 2) PID, program counter, CPU registers, memory-management info (page table base) — other valid answers: state, scheduling info, I/O list. 3) Preemption (time-slice expiry), arrival of a higher-priority ready thread, or a voluntary yield.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?