Android from the foundation · Puzzle 1 of 16

The kernel is in charge

Something has to share the phone between all those processes. That's the core of the phone's own software, and it's the only thing that can reach into every process.

The problem

In puzzle 0, every running app was its own process with its own memory. But the phone has one CPU (the chip that runs a program's instructions, one after another; real phones have a few, but picture one) and one pool of memory for all of them. Who decides which process runs right now, and who hands out the memory?

See it

Two app processes stand on the kernel; the kernel moves the CPU between them and hands memory to one that asks kernel Notes Music CPU + memory
  1. Under all the processes runs the phone's own software, the operating system (Android, built on Linux, an operating system first made for computers shared by many people). Its core is the kernel: the ground every house stands on.

    Step 1 of 4
  2. There's one CPU. The kernel gives it to Notes for a moment…

    Step 2 of 4
  3. …then to Music, then back, many times a second, so both seem to run at once. Predict: Notes needs more memory. Who does it ask?

    Step 3 of 4
  4. The kernel. It hands out memory, and it's the only one that can reach into every process.

    Step 4 of 4

The building block

The phone runs its own software underneath the apps: the operating system. Android is an operating system, built on Linux: a free operating system first made for computers shared by many people.

At its core is the kernel. It shares the CPU between processes, switching between them many times a second, so they all seem to run at once. It hands out memory, and it opens files. Because the kernel hands out every process's memory, it can reach into any process. A process can only reach the memory it was given.

The analogy

The processes are houses on a street. The kernel is the street's management: it decides who gets electricity right now, hands out building space, and is the only one who can enter every house.

Check yourself

One CPU, two apps both busy. How do both get work done?

Right. The kernel shares the CPU by switching between processes very often.

Not quite. The phone has the CPU; processes only get turns on it, handed out by the kernel.

Not quite. If one ran until it finished, the other would freeze. The kernel switches between them constantly.

An app needs more memory. Who gives it?

Not quite. A process can't reach another's memory. Only the kernel hands memory out.

Right. Memory is handed out by the kernel; processes ask for it.

What's the difference between the kernel and the operating system?

Right. Android is the operating system; the kernel is its core.

Not quite. The kernel is inside the operating system: its core, under everything else.

Sources

What you now know

Processes never deal with the CPU or memory directly. They ask the kernel, which shares them out and keeps every process in its place.