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 04 · How Computers Work · Inside the operating system · with code: Python · about 20 min to read

Play it as a journeyTutor comes with a plan

Whose turn, and who decides

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

The kernel handing out turns on a few cores to many programs. This lesson asks the question the drawing takes for granted: when several programs are waiting, which one goes next?

Before you start. The CPU is the chip that runs a program’s instructions. A core is one of several copies of that machinery inside it, each running one program at a time. The kernel is the one program with full access to the hardware, and its scheduler gives each running program a short turn on a core, then takes it back and gives the next one a turn (Processes, Threads & the Kernel). Every swap from one program to another costs a little time, because the core has to save one program’s place and load the next one’s.

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

  • March 2007: an anaesthetist rewrites who goes next
  • One photocopier, four people: first come, first served
  • Shortest first: the best average, if you can see the future
  • Taking turns, and the dial: the time slice
  • Guessing from behaviour: the multilevel feedback queue
  • Kolivas’s answer: count what each has had

Terms it explains: response time, turnaround time, time slice, multilevel feedback queue, fair-share scheduling, FIFO, SJF, round robin, MLFQ, 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