---
title: "Processes, Context Switches and What They Cost"
description: "A process is an active program instance with execution state and OS-managed resources. It may be ready, running or blocked. A process switch saves and restores CPU execution state and selects the next"
canonical: https://lightmysky.com/learn/computing/processes-context-switches-and-what-they-cost-mt_oiOwHKUoXG
source: https://lightmysky.com/learn/computing/processes-context-switches-and-what-they-cost-mt_oiOwHKUoXG.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Processes, Context Switches and What They Cost

A process is an active program instance with execution state and OS-managed resources. It may be ready, running or blocked. A process switch saves and restores CPU execution state and selects the next process's existing address-space context. Memory mappings and open-file records remain stored, rather than being copied into saved CPU state. Context handling takes time; added cache costs depend on hardware and workload.

Subject: Computing · Area: Computer Systems · Ages 19 to 20
Page: https://lightmysky.com/learn/computing/processes-context-switches-and-what-they-cost-mt_oiOwHKUoXG

## Ready when they can

- Distinguish saved and restored CPU context from process memory and resource records that remain stored
- Follow a process through the ready, running and blocked states
- Explain why a switch costs more than the register copying suggests

## Lesson: What a context switch really moves

You have followed requests into the kernel. The kernel also tracks processes: active instances of programs with execution state, memory and resources such as open files. A process still exists when it is not executing. One application may use several processes, and several processes may run the same program.

*(drawing: Ready means able to run but waiting for a CPU. Running means executing. Blocked means waiting for an event. An event makes it ready, not immediately running.)*

An address space is the memory-address view available to a process. In this simplified model of single-threaded processes, the kernel saves A's CPU execution state, selects B's existing address-space context, restores B's saved CPU state, and resumes B. Saved CPU state includes the instruction position and required register values. Its exact contents depend on the processor and OS. A blocking request can let the kernel schedule another ready process.

A switch need not clear caches. Some needed instructions or data may remain cached. A missing line causes a miss in that cache and a fetch from a lower memory level, which may be another cache or main memory. Competing working sets may evict useful lines. The added cost depends on the cache hardware, what remains cached and the incoming process's accesses.

Saving and restoring context and running scheduler code take time even when needed data remains cached. More frequent switches can leave less time for program work, and cache disruption can add further cost. The size of the effect depends on the hardware, workload and implementation. A switch is not necessarily harmful: it can let useful work proceed while another process waits.

A paused process retains its memory mappings and open-file records. A switch selects the next process's existing address-space context, which tells the hardware how to use that process's mappings. It does not copy every memory byte or recreate its open files. Saving CPU execution state differs from retaining these resources. Address-space selection can require hardware-control updates; the details and cost depend on the processor and OS.

For a register-copy count, specify how many individual copies each switch performs, including both saving and restoring. Multiply that total by the number of switches. In a toy model, two switches with twelve total register copies each perform 2 × 12 = 24 copies. This counts copies only, not scheduler time or cache costs.

**Recap.** A process can be ready, running or blocked. Switches save and restore CPU state, select address-space context and retain resources. Context work takes time; cache costs vary by hardware and workload.

*Original lesson, questions and flashcards written for this dataset.*

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [What an Operating System Is: Privilege and System Calls](https://lightmysky.com/learn/computing/what-an-operating-system-is-privilege-and-system-calls-mt_0kMavEKxpX)

## Optional connections

- [The Memory Hierarchy and Why Caching Works](https://lightmysky.com/learn/computing/the-memory-hierarchy-and-why-caching-works-mt_0f5ArFPlxP)

## Opens up

- [Virtual Memory and Address Translation](https://lightmysky.com/learn/computing/virtual-memory-and-address-translation-mt_B-PiAyderj)
- [Scheduling: Deciding Which Process Runs Next](https://lightmysky.com/learn/computing/scheduling-deciding-which-process-runs-next-mt_QZYzfVIcP6)
