Programs, the processor and memory

Unit 2 of 5 in How computers and the internet work.

You will be able to describe what a running program is doing and why every program gets its own view of memory.

Lesson

What a running program does

A running program does one simple thing: it executes instructions. The processor fetches an instruction from memory, works out which instruction it is, and does it. That might be adding two numbers, reading memory, checking a condition or jumping to another function. Then it moves to the next instruction.

This fetch, decode, execute cycle is the basis of the Von Neumann model of computing, and it happens millions or billions of times a second. Everything you run, from a terminal to a browser, comes down to it.

Memory holds both the program and its data

Instructions are fetched from memory, and the data the program works on also lives in memory. So a program is a list of instructions plus the space it uses while it runs. Reading the assembly a compiler produces, as one of this unit's labs does, shows you those instructions in a form a person can read.

Virtual memory: each program gets its own map

Physical memory is a limited resource, and it is not always one continuous block. Dealing with it directly would be complicated, so computers use virtual memory. Each memory access uses a virtual address, and the processor translates it into a physical one.

The kernel documentation lists what this buys: it hides the details of physical memory from programs, keeps only the needed information in physical memory, and provides protection and controlled sharing of data between processes. The translation uses page tables, organized in levels, with the top-level pointer held in a processor register.

For security the key point is protection. Because each process works with its own virtual addresses, one process cannot simply read another's memory unless the system has set up sharing on purpose.

Key points

Sources

Practice in the labs

See a program as instructions. One beginner lab is enough here; the aim is to read, not to master assembly.

Knowledge check

  1. In plain words, what does a running program do? Answer: Executes instructions one after another. The processor fetches an instruction from memory, decodes it, executes it and moves on to the next, as the OSTEP introduction describes.
  2. Which of these is a benefit of virtual memory listed in the kernel documentation? Answer: Protection and controlled sharing of data between processes. The kernel's virtual memory primer says it abstracts physical memory, keeps only needed data in it, and provides protection and controlled sharing between processes.
  3. What turns a virtual address into a physical one? Answer: Page tables used by the processor's translation. Mappings are described by page tables, and the processor uses them to translate the address a program uses into a physical memory address.

Back to the syllabus or see all classes.

Related