Processes: States, the Process Control Block and Interrupts

UNIT 2 • MODULE 3 • LESSON 03

Right now your phone is probably playing music, checking for messages, keeping the clock up to date and drawing the screen, all on one or a few processor cores. Each of those jobs gets the processor for a tiny moment, is paused, and gets it back a moment later, thousands of times a second. The part of the operating system that organises all this is process management, and its tools are process states, the process control block and interrupts.

This lesson explains what a process is, the states a process moves through and why, what the OS records about each process, and how an interrupt lets the OS take back control of the processor. Lesson 04 then looks at how the OS chooses which ready process runs next, and what happens when processes get stuck waiting for each other.

What you will learn

  • The difference between a program and a process.
  • The three main process states: Running, Ready and Blocked, and the events that move a process between them.
  • What a process control block (PCB) stores and why.
  • What a context switch is.
  • What an interrupt is, the main kinds of interrupt, and the steps the processor and OS follow to handle one.

Part 1: Programs and processes

A program is a set of instructions stored in a file, such as the compiled C programs you wrote in Unit 1. It does nothing while it sits on the disk. A process is a program in execution: it has been loaded into memory, it has a current position (its program counter), values in its variables and registers, files it has opened and a share of processor time.

ProgramProcess
Passive: instructions in a fileActive: a program being executed
Stored on secondary storageHeld in main memory while it runs
One copy on the diskCan have several processes from the same program (two browser windows)
Has no stateHas a state, a program counter, register values and allocated resources

Process management includes creating processes, deciding which one runs, pausing and resuming them, letting them share resources safely, and removing them when they finish. Both user programs and system programs (the OS’s own helpers) run as processes.

Part 2: Process states

With one processor core, only one process can be executing at any instant. Every other process is either able to run but waiting its turn, or unable to run because it is waiting for something. That gives three main states:

StateMeaning
RunningThe process’s instructions are being executed by the processor right now. One per core.
ReadyThe process could run immediately if it were given the processor. Ready processes wait in the ready queue.
Blocked (also called Waiting)The process cannot continue until some event happens, usually the end of an input or output operation, such as a key press, a disk read or a network reply.
The three main process states Ready Running Blocked dispatched time slice over waits for I/O I/O complete ends: Finished
There is no arrow from Blocked straight to Running. A process whose input has arrived must queue as Ready first.

The transitions and what causes them

TransitionTypical cause
Ready → RunningThe scheduler picks this process and dispatches it, because the processor has become free.
Running → ReadyPre-emption: the time slice ends (a timer interrupt), or a higher-priority process becomes ready.
Running → BlockedThe process requests input/output or another resource and must wait for it.
Blocked → ReadyThe event it was waiting for happens, for example the I/O completes and the device sends an interrupt.
Running → FinishedThe process ends normally or is stopped because of an error.

Many textbooks add a New state (being created) and a Terminated or Exit state (finished, being cleaned up). The syllabus focuses on Running, Ready and Blocked, so make sure you know those three and the causes of each arrow. Note especially that a blocked process never goes straight to Running; when its data arrives it rejoins the ready queue and waits its turn.

Use the animator to move three processes through their states. Follow the challenges, and try an event that is not allowed to see why.

Try it 1Process state animator

One CPU, three processes. Each button is an event. Watch which state each process moves to.

Transition log



Part 3: The process control block

When a process is paused, everything it needs to carry on later must be saved somewhere. The OS keeps a data structure for every process called the process control block (PCB), also called the process descriptor. All the PCBs together form the OS’s process table. Think of a PCB as the record a nurse keeps for each patient on a ward: who they are, their current condition, what they are waiting for and what has been done so far.

PCB fieldWhat it holds
Process ID (PID)A unique number identifying the process
Process stateRunning, Ready or Blocked (and New or Terminated)
Program counterThe address of the next instruction to execute
Register contentsSaved values of the CPU registers when the process was paused
Scheduling informationPriority, time already used on the CPU, position in queues
Memory informationWhere the process’s code and data are in memory (for example its page table, Lesson 05)
I/O and file informationOpen files and devices the process is using or waiting for
Accounting informationCPU time used, time limits, owner’s user ID

If you have studied Records in C: Grouping Data with struct, you can picture a PCB as a C struct:

typedef struct {
    int  pid;
    int  state;   /* 0 ready,
                     1 running,
                     2 blocked */
    long pc;      /* program counter */
    long regs[16];
    int  priority;
    long cpuTimeUsed;
    int  openFiles[8];
} PCB;

Context switching

Moving the processor from one process to another is called a context switch. The OS saves the running process’s program counter and registers into its PCB, updates its state, picks the next process, and loads that process’s saved values from its PCB into the processor. The new process continues exactly where it left off, unaware it was ever paused. Context switches take a little time in which no useful user work is done, so an OS tries not to switch more often than necessary.

Part 4: Interrupts

How does the OS get the processor back from a running process? The process will not hand it over politely, and the OS itself is not running while the user’s process is. The answer is the interrupt: a signal to the processor that some event needs attention. When it arrives, the processor finishes its current instruction, puts the running work aside and jumps to a piece of OS code that deals with the event.

Kind of interruptExample
Input/output (hardware)The disk has finished reading a block; a key has been pressed; a network packet has arrived
TimerThe time slice for the running process has ended
Hardware failurePower is failing; a memory parity error has been detected
Program (software) errorDivision by zero; an attempt to access memory the process does not own
System call (trap)The process asks the OS for a service, such as opening a file

How an interrupt is handled

The exact steps vary between processors, but this sequence is what CAPE answers should describe:

1. A device or timer sends an
   interrupt signal.
2. The CPU finishes the current
   instruction.
3. The CPU checks for interrupts
   (at the end of each fetch-
   decode-execute cycle).
4. The current process's PC and
   registers are saved (in its PCB
   or on a stack).
5. The CPU identifies the source
   and jumps to the matching
   interrupt service routine (ISR).
6. The ISR handles the event, e.g.
   marks a blocked process Ready.
7. The scheduler chooses which
   process runs next.
8. That process's saved values are
   restored and it continues.

Interrupts have priorities. A power-failure interrupt must be handled before a key press. While a high-priority interrupt is being serviced, lower ones are held back; a higher one can interrupt the ISR itself.

A worked story

A student is editing a spreadsheet (process S) while a music player (process M) streams a song. S is running. The student clicks Open, so S asks the OS to read a file from the SSD. S moves from Running to Blocked and the scheduler dispatches M (Ready to Running). A few milliseconds later the SSD finishes and raises an I/O interrupt. The CPU saves M’s context, runs the disk ISR, which copies the data and marks S Ready. The scheduler then lets M continue (or picks S, depending on the scheduling rule). When S is next dispatched it carries on with the file in memory.

Try it 2Order the steps of interrupt handling

Tap the steps in the order they happen, starting when a device signals that its input is ready.

Your order so far

    Tap the step that comes next

    Polling: the alternative

    Without interrupts, the OS would have to keep asking each device "are you finished yet?" That is called polling. It wastes processor time when devices are slow, which is why interrupts are preferred for most devices. Lesson 07 compares the two.

    Try it 3Which transition happens?

    Each event happens to one process. Choose the state change it causes. Ten items.

    Part 5: Common mistakes

    • Blocked straight to Running. Not allowed. A process whose I/O completes goes to Ready.
    • Confusing Ready and Blocked. Ready means "could run now, waiting for the CPU". Blocked means "cannot run, waiting for an event".
    • Vague causes. Say what event causes a transition: "the time slice ends", "it requests input from the keyboard", "the disk read completes".
    • Leaving out the save step. Any description of interrupt handling must say that the current state (program counter and registers) is saved first and restored later.

    Try it 4Process and interrupt drill

    Pick a mode. "States" asks where a process goes after an event. "PCB" asks what the process control block stores.

    Summary

    IdeaRemember
    ProcessA program in execution, with its own state and resources.
    StatesRunning (on the CPU), Ready (waiting for the CPU), Blocked (waiting for an event).
    Key arrowsDispatch: Ready→Running. Time slice over: Running→Ready. I/O request: Running→Blocked. I/O done: Blocked→Ready.
    PCBPID, state, program counter, registers, priority, memory and file details, accounting.
    Context switchSave one process’s context to its PCB; load another’s.
    InterruptSignal that makes the CPU save its work, run an ISR, then let the scheduler choose.

    Review questions

    1. Distinguish between a program and a process.

    Show answer

    A program is a passive set of instructions stored in a file. A process is a program in execution, loaded in memory, with a program counter, register values, a state and allocated resources.

    2. Name and describe the three main process states.

    Show answer

    Running: being executed by the CPU. Ready: able to run, waiting in the ready queue for the CPU. Blocked: unable to run until an event such as I/O completion happens.

    3. Give a situation that would move a process from Ready to Running.

    Show answer

    The processor becomes free (the running process blocks, finishes or is pre-empted) and the scheduler selects this process to run.

    4. Give a situation that would move a process from Running to Blocked.

    Show answer

    The process requests input or output, for example reading from a disk or waiting for a key press, and cannot continue until it completes.

    5. Why can a blocked process not move directly to Running?

    Show answer

    When its event completes it becomes able to run, but the CPU may be in use and other processes may be waiting. It joins the ready queue and the scheduler decides when it runs.

    6. List four items stored in a process control block.

    Show answer

    For example: process ID, process state, program counter, register contents, priority, memory information, open files, CPU time used.

    7. What is a context switch and why is the PCB needed for it?

    Show answer

    Changing the CPU from one process to another. The PCB stores the paused process’s program counter and registers so it can continue later exactly where it stopped.

    8. Explain how an interrupt from a disk is handled.

    Show answer

    The disk signals the CPU. The CPU finishes its current instruction, saves the running process’s context, and runs the disk’s interrupt service routine. The ISR deals with the data and marks the waiting process Ready. The scheduler chooses a process to run and its context is restored.

    Homework

    1. Draw the state diagram from memory and label every arrow with its cause.
    2. Write your own short story (like the spreadsheet example) in which a process goes Ready → Running → Blocked → Ready → Running → Finished. Name the event for each step.
    3. Rank these interrupts from highest to lowest priority and justify: key press, power failure, timer, printer out of paper.
    4. Extend the PCB struct above with two more fields you think the OS would need, and say why.

    Mastery quiz: Processes, the PCB and Interrupts

    This 10-question quiz is separate from the short Quick quiz at the end of the lesson. Score 8/10 or higher to earn this lesson’s badge. Your best score is saved in this browser on this device.

    Mastery quiz: Processes: States, the Process Control Block and Interrupts

    Your course badges: loading saved progress…

    View badges

      No course badges earned yet. Score 8/10 in a lesson quiz to earn its badge.

      Saved in this browser on this device. Clearing browser data may remove your badges.

      Answer all 10 questions. Earn this lesson’s badge at 8/10 or higher. Read the explanations, revisit the Try it activities and retry as often as you need. These are self-study badges, not formal grades.

      1. A process is...
      2. Which state means "able to run, waiting for the CPU"?
      3. A running process requests data from the keyboard. Its new state is...
      4. The keyboard data arrives for a blocked process. It moves to...
      5. Which is NOT normally stored in a PCB?
      6. Saving one process’s registers and loading another’s is called...
      7. Which event causes Running → Ready?
      8. When an interrupt arrives, the CPU first...
      9. The code that deals with an interrupt is the...
      10. Repeatedly asking a device whether it is finished is called...

      Exam tips

      Specimen Unit 2 Paper 02 (2021), Question 5(b). You must give situations that cause two state changes. Name a concrete event (for example "the CPU becomes free and the scheduler selects it" or "it waits for a device that is in use"). Use a different program from the one in the question when practising so you understand the idea, not one example.

      Specimen Unit 2 Paper 02 (2021), Question 5(c). Describing interrupt handling earns marks for each stage: the interrupt is raised, the current work is saved (context switch), the ISR runs, and the original process continues (or moves through Blocked and Ready). Use the eight-step list in Part 4 as your checklist.

      Specimen Unit 2 Paper 01 (2021), Items 32, 34 and 45. These test what a PCB contains, which labels are real process states, and which transition happens when a blocked process’s input becomes available. Remember: "Completed" or "Finished" is not one of the three syllabus states, and blocked processes go to Ready, not Running.

      Past paper practice. 2018 Unit 2 Paper 02 Question 5 and 2019 Unit 2 Paper 02 Question 5 both test process states. Worked answers are on the CS Solutions page.

      Previous: Unit 2 • Module 3 • Lesson 02 – How Operating Systems Evolved: From Batch Jobs to Multi-User Systems. Next: Unit 2 • Module 3 • Lesson 04 – CPU Scheduling and Deadlock.

      Syllabus link: CAPE Computer Science (CXC A19/U2/21), Operating Systems and Computer Networks (Unit 2, Module 3). Specific Objective 3: describe the functions of operating systems (process management: definition; process states Running, Ready, Blocked; how the interrupt mechanism works; the process control block (process descriptor)).

      Video search terms

      Search YouTube for: "process states ready running blocked", "process control block explained", "how interrupts work interrupt service routine".

      Try it 5Quick quiz

      Tap an answer. All eight questions are self-checks on this lesson.

      Updates

      2026/12/01

      - First version of the lesson.

      © 2026 islandclass.org

      Leave a Reply