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 06 · How Computers Work · Build the machine's software · with code: Python · about 20 min to read

Play it as a journeyTutor comes with a plan

The program that starts programs

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

The kernel handing each program its own walled-off memory and its own turn on the chip. This lesson builds the ordinary program that asks the kernel for those walls, one command at a time: the shell.

Before you start. A process is one running program, walled off so nothing else can touch its memory. The kernel is the one program that can make new ones (Processes, Threads & the Kernel). Picture each process with numbered doors: when it opens a file, the kernel hands it a number, and the program reads and writes through that door. The numbers are file descriptors (I/O, Interrupts & the Bus). Part one of this build made a small machine that runs instructions (Build a stack machine). This part builds the program that starts other programs.

Lesson 34 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

  • 1969-70, on the PDP-7: the day cd stopped working
  • Make a copy of yourself: fork
  • Become someone else: exec, then wait
  • Why cd lives inside the shell: the builtin
  • Rewiring the doors before the change: redirection
  • A tube between two performers: the pipe
  • Ctrl-C rings for everyone: the signal

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

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