Operating Systems

Process Control Block (PCB); Process States; CPU Scheduling

C-CAT

Process Control Block (PCB)

What is a PCB?

The PCB (Process Control Block) is the data structure used by the OS to store all information about a process.

Also called: Task Control Block (TCB)

PCB Contents

FieldDescription
Process ID (PID)Unique identifier for the process
Process StateNew, Ready, Running, Waiting, Terminated
Program Counter (PC)Address of next instruction to execute
CPU RegistersContents of all CPU registers (saved on context switch)
CPU Scheduling InfoPriority, scheduling queue pointers
Memory Management InfoBase register, limit register, page/segment tables
I/O Status InfoList of open files, I/O devices allocated
Accounting InfoCPU time used, elapsed time, job limits
Parent PID (PPID)PID of parent process
User ID (UID)Owner of the process

Process States

Five-State Process Model

                    +--------+
                    |  NEW   |  ← Process created
                    +--------+
                         | admitted
                         ↓
              +------READY------+
              |    ←scheduler   |
              |   dispatch      |
              ↓                 |  interrupt / time slice
         +--------+             |
         |RUNNING |→→→→→→→→→→→→+
         +--------+
              |
              | Wait for I/O or event
              ↓
         +--------+
         |WAITING |  ← process blocked for I/O
         | (BLOCKED)|
         +--------+
              |
              | I/O or event complete
              ↓
         READY (returns to Ready queue)

         RUNNING → TERMINATED (exit)

Process States Explained

StateDescriptionTransitions
NewProcess is being created→ Ready (after creation)
ReadyIn memory, waiting for CPU→ Running (scheduler dispatches)
RunningActually being executed on CPU→ Ready (time slice expires) / Waiting (I/O) / Terminated (exit)
Waiting (Blocked)Waiting for I/O completion or event→ Ready (I/O/event done)
TerminatedProcess has finished executionEnd state

Context Switch

When CPU switches from one process to another:

Process A running on CPU
    |
    | Interrupt / time expired
    ↓
Save CPU state of A → PCB_A
Load CPU state of B ← PCB_B
    |
    | Process B now running on CPU

Context switch overhead: Saving and restoring registers, cache flush — expensive!

CPU Scheduling

What is CPU Scheduling?

CPU Scheduling selects which process in the Ready queue gets the CPU next.

Why scheduling?

  • CPU can only run one process at a time
  • Multiple processes compete for CPU
  • OS must decide who runs next

Scheduling Queues

New Process → Job Queue
                 ↓
         Ready Queue (in RAM)
                 ↓
         CPU Scheduler picks one
                 ↓
         CPU executes process
                 ↓
     I/O request? → I/O Wait Queue → I/O done → Ready Queue
     Time slice?  → Preempted → Ready Queue
     Exit?        → Terminated

Scheduling Criteria (Performance Metrics)

MetricDescriptionOptimize
CPU UtilizationPercentage of time CPU is busyMaximize
ThroughputNumber of processes completed per time unitMaximize
Turnaround TimeTotal time from submission to completionMinimize
Waiting TimeTotal time process spends in ready queueMinimize
Response TimeTime from submission to first responseMinimize

Formulas:

Turnaround Time = Completion Time - Arrival Time
Waiting Time    = Turnaround Time - Burst Time
Response Time   = First CPU given - Arrival Time

Preemptive vs Non-Preemptive Scheduling

TypeDescription
Non-PreemptiveOnce CPU is given to a process, it keeps it until done or waiting for I/O
PreemptiveOS can forcibly take CPU from running process (time slice, priority)

Continue learning

Related notes

Put this topic into timed practice

Open mock tests when you want full-exam pacing, or keep drilling in practice mode.