RTUComputer ScienceYr 2024 · Sem 52024

Q1Operating System

Question

10 marks

(a) Explain the Process Control Block (PCB) in detail. (b) Describe the different states of a process with a state transition diagram.

Answer

The PCB stores all information needed to manage a process, while the process state transition diagram shows how processes move between states during their lifetime.

The Process Control Block (PCB), also called the Task Control Block, is the data structure used by the OS kernel to store all information about a process. Each process has exactly one PCB. The OS uses PCBs to manage, schedule, and control processes. When a context switch occurs, the current process's state is saved in its PCB and the next process's state is restored from its PCB.

Process Control Block Structure
Figure 1: Structure of a Process Control Block (PCB)

  • Process State: Current state of the process (new, ready, running, waiting, terminated).
  • Process ID (PID): Unique identifier for each process.
  • Program Counter (PC): Address of the next instruction to be executed.
  • CPU Registers: Contents of all CPU registers (accumulators, index registers, stack pointer, general-purpose registers) that must be saved and restored on context switch.
  • CPU Scheduling Information: Process priority, scheduling queue pointers, and other scheduling parameters.
  • Memory Management Information: Base and limit registers, page tables, or segment tables depending on the memory system used.
  • Accounting Information: CPU time used, elapsed real time, time limits, account numbers, job or process numbers.
  • I/O Status Information: List of I/O devices allocated to the process, list of open files, pending I/O requests.

A process passes through a series of distinct states during its lifetime. The process state is stored in the PCB and is updated by the OS.

Process State Transition Diagram
Figure 2: Process State Transition Diagram showing five states

  • New: The process is being created. The OS is setting up the PCB and allocating resources. Transition: New → Ready (after admission by the OS long-term scheduler).
  • Ready: The process is waiting to be assigned to the CPU. It has all resources except the CPU. Multiple processes can be in the ready state simultaneously (ready queue). Transition: Ready → Running (short-term scheduler dispatches it).
  • Running: The process is currently executing on the CPU. Only one process per CPU core can be in running state. Transitions: Running → Waiting (process requests I/O or event), Running → Ready (preempted by scheduler or time quantum expires), Running → Terminated (process finishes).
  • Waiting (Blocked): The process is waiting for an event (I/O completion, signal, resource). Cannot proceed until the event occurs. Transition: Waiting → Ready (I/O completes or event occurs).
  • Terminated: The process has finished execution. The OS deallocates its resources and removes its PCB. Also called the exit state.

In some models, two additional states are added: Suspended Ready and Suspended Waiting, to handle swapping of processes to disk when memory is insufficient. The medium-term scheduler handles these transitions (swap in/swap out).

Back to Paper