The program that runs the programs
Your laptop runs hundreds of programs on a handful of CPU cores, each believing it has the machine to itself. The kernel makes that illusion: it shares the CPU (scheduling), memory (virtual memory), files and devices — and protects programs from each other.
Programs can't touch hardware directly. They ask the kernel with a system call — exactly the ecall you used in Assembly. The CPU switches into kernel mode, does the privileged work, and switches back.
A process's life
A process is a running program: its code, memory and registers. It moves between states — *ready* to run, *running* on a core, *blocked* waiting for disk or network, and finally *terminated*.
const MOVES = {
new: { admit: "ready" },
ready: { dispatch: "running" },
running: { timeout: "ready", wait: "blocked", exit: "terminated" },
blocked: { wake: "ready" },
terminated: {},
};
function transition(state, event) {
const next = MOVES[state]?.[event];
if (!next) throw new Error(`Can't ${event} from ${state}`);
return next;
}
function lifecycle(events) {
let state = "new";
const path = [state];
for (const e of events) {
state = transition(state, e);
path.push(state);
}
return path;
}