Three states
A process is a running program. At any moment it is in exactly one of three states: running (on the CPU now), ready (could run, but waits for the CPU) or blocked (waits for something else, such as the disk).
We start two processes, A and B, on a computer with one CPU. The kernel writes ready as the state in each one's process control block (PCB) and puts both in the ready queue, a line waiting for the CPU.
Waiting for the disk
The scheduler, the part of the kernel that picks who runs next, takes A from the front of the queue. The kernel loads A's saved registers and A runs on the CPU in ticks 1 and 2. B stays ready.
At the end of tick 2, A calls read() to get data from the disk. The disk is slow, so the kernel starts it working, marks A blocked and takes A off the CPU. The scheduler never picks a blocked process.
The CPU is free, so the scheduler dispatches B. B runs in ticks 3 and 4 while the disk fetches A's data. Blocking lets the CPU and the disk work at the same time.
At the end of tick 4 the disk finishes and raises an interrupt. The kernel marks A ready, not running: B still holds the CPU and keeps running in tick 5.
The timer and the end
B has now run for 3 ticks, its whole time slice. A timer interrupt hands the CPU back to the kernel, which moves B to the back of the ready queue and dispatches A. Taking the CPU away like this is preemption.
A runs ticks 6 and 7, carrying on right after its read(), because its registers were saved in its PCB. Then A calls exit(). The kernel marks it done and the CPU is free again.
The scheduler dispatches B again. It runs its last 3 ticks, 8 to 10, and exits. In all 10 ticks the CPU was never idle, even though A spent 2 ticks blocked.
The kernel moves processes on four arrows: dispatch (ready to running), preempt (running to ready), wait (running to blocked) and wake (blocked to ready). A blocked process always wakes to ready, never straight to running.
What happens
;; step 1/10 · states state meaning can it use the CPU? running its instructions run on the CPU it is using it ready it could run right now yes, when picked blocked it waits for an event (disk ...) no, not until the event one CPU runs one process at a time, so all the others are ready or blocked.
A tick here is a made-up unit of time to keep the numbers small. Real systems set the timer to interrupt every few milliseconds, and a disk read takes far longer than a time slice. Systems use other names for the same states. xv6 calls them RUNNING, RUNNABLE and SLEEPING. Linux ps shows R for both running and ready (runnable, on the run queue) and S or D for sleeping, its word for blocked.