Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 03 · How Computers Work · Many programs, one machine · about 16 min to read

Play it as a journeyTutor comes with a plan

Processes, Threads & the Kernel

Processes Threads and the Kernel
Processes Threads and the Kernel · Open board

The one program standing between every other program and the real machine, handing out turns on the chip and private-looking slices of memory so a handful of real cores can serve hundreds of programs at once.

Before you start. The last lesson, How Code Becomes Execution (compilers, stack & heap), left one program’s instructions running as a single stream on the CPU, fetched and carried out one at a time, as if that program owned the chip outright. This lesson is about the hundreds of programs actually doing that on the same handful of cores at once, and the one piece of software that keeps them from reading or overwriting each other.

Lesson 9 of 41 in How Computers Work

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1961: waiting in line for the only computer
  • One computer, one program in charge of sharing it
  • Each program gets a process, and a wall around it
  • One process, two hands: the thread
  • The address that isn’t where it says
  • Whose turn it is, a thousand times a second

Terms it explains: kernel, process, thread, virtual memory, scheduler, syscall, TLB, page fault, context switch, segfault, fork/exec, init/systemd, MMU + page table, namespaces + cgroups, page (~4KB) / frame, PID, preemption, swap, user vs kernel mode (ring 3/0).

Lab

The program needs twelve pages at once. What happens when it gets eleven frames?

Drag Frames of real memory from 24 down to 11, then back to 12, and watch Time spent working.

Open The working set

Three long jobs are running when you press a key. How long until the keypress gets the CPU?

Click Take turns, drag How long one turn lasts from 100 ms down to 1 ms, and watch The keypress waits.

Open The time slice

How many workers should a pool have, and why does the answer flip when the tasks mostly wait?

Drag Workers on shift down to the core count, then push Share of each task spent waiting to 90% and watch Finished each second.

Open The thread pool

Related papers

Review How Computers Work