Process states: ready, running and blocked
About this lesson
A computer with one CPU can only run one process at a time, yet it juggles many. The kernel does it by keeping every process in one of three states: running on the CPU, ready and waiting for a turn, or blocked waiting for something slow such as the disk. Follow two processes, A and B, through ten ticks of time as A waits for a disk read, B takes the CPU, the disk wakes A up and the timer takes the CPU back from B. The lesson on the process (address space, registers and the PCB) introduces the PCB that records each state, and the Linux lesson on processes and signals shows the same states in ps.
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).
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.
Read the lesson step by step
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).
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.Two processes start
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.
the plan (time counted in ticks): A 2 ticks of work, read() from the disk, 2 more ticks B 6 ticks of work time slice 3 ticks · a disk read takes 2 ticks PCB states A ready B ready ready queue [A, B] (front first)Ready to running
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.
dispatch: ready -> running t1 A running B ready t2 A running B ready ready queue [B]Running to blocked
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.
wait: running -> blocked A's system call, in C99 + POSIX: #include <fcntl.h> #include <stdio.h> #include <unistd.h> int main(void) { char buf[512]; int fd = open("data.bin", O_RDONLY); if (fd < 0) return 1; ssize_t n = read(fd, buf, sizeof buf); /* may block: A waits for the disk */ printf("read %zd bytes\n", n); close(fd); return 0; } kernel sends the request to the disk PCB A blocked (waits for the disk)The CPU keeps busy
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.
dispatch: ready -> running t3 A blocked B running t4 A blocked B running ready queue [] disk reading for ABlocked to ready
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.
wake: blocked -> ready disk interrupt: A's data is here t5 A ready B running ready queue [A]Running to ready
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.
end of t5 timer: B used its 3-tick slice preempt B: running -> ready (back of the queue) dispatch A: ready -> running t6 A running B readyA finishes
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.
exit: running -> done read() returned 512 (bytes read) t6 A running B ready t7 A running B ready PCB A doneB finishes
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 whole trace: t1 A running B ready t2 A running B ready t3 A blocked B running t4 A blocked B running t5 A ready B running t6 A running B ready t7 A running B ready t8 A done B running t9 A done B running t10 A done B running CPU busy 10 of 10 ticksFour arrows
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.
the scheduler as a Python simulation: from collections import deque SLICE, IO_TICKS = 3, 2 left = {"A": [2, 2], "B": [6]} # CPU bursts; A reads the disk between state = {"A": "ready", "B": "ready"} ready, io, running, used = deque("AB"), {}, None, 0 t = 0 while any(s != "done" for s in state.values()): t += 1 if running is None and ready: # dispatch running, used = ready.popleft(), 0 state[running] = "running" print(t, state["A"], state["B"]) for p in list(io): # the disk works io[p] -= 1 if io[p] == 0: # wake del io[p]; state[p] = "ready"; ready.append(p) if running is None: continue p = running left[p][0] -= 1; used += 1 if left[p][0] == 0: left[p].pop(0) if left[p]: # wait for the disk state[p] = "blocked"; io[p] = IO_TICKS else: # exit state[p] = "done" running = None elif used == SLICE: # preempt state[p] = "ready"; ready.append(p); running = None prints: 1 running ready 2 running ready 3 blocked running 4 blocked running 5 ready running 6 running ready 7 running ready 8 done running 9 done running 10 done running
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01A process could run right now, but another process is using the only CPU. Which state is it in?
Ready means it has everything it needs except the CPU. Blocked would mean it is waiting for an event, such as a disk read, and could not run even if the CPU were free.
02Process A calls read() and the data must come from the disk. What does the kernel do?
A blocked process cannot use the CPU, so the kernel lets another process run while the disk works. In the example, B runs in ticks 3 and 4 while the disk fetches A's data.
03The disk finishes A's read while B is running. What is A's state now?
A blocked process always wakes to ready. Whether it then runs at once is the scheduler's choice; in the example B keeps the CPU for tick 5 and A waits in the ready queue.
04B never asks for I/O. How does the kernel get the CPU back from it?
The timer interrupts the CPU at regular intervals so the kernel runs again. When B has used its time slice (3 ticks here), the kernel moves it from running to ready and dispatches another process.
05In Linux, ps shows R for a process. What can you tell?
The ps manual says R means running or runnable (on run queue): Linux does not separate running from ready in that column. Blocked processes show S or D, and Z is a zombie.
Glossary
- Process
- A running program: its code, its memory, its registers and the kernel's record of it.
- Running
- The state of the process whose instructions are executing on a CPU right now. One per CPU at most.
- Ready
- The state of a process that could run but is waiting for the CPU. Ready processes wait in the ready queue.
- Blocked
- The state of a process waiting for an event, such as a disk read, that cannot run until the event happens. Also called waiting or sleeping.
- Scheduler
- The part of the kernel that picks which ready process runs next. Moving a process from ready to running is called dispatching it.
- Preemption
- Taking the CPU away from a running process that did not give it up, usually after a timer interrupt, and putting it back in the ready queue.
- Time slice
- How long the scheduler lets a process run before it may be preempted. It is 3 ticks in this lesson's example.
- Process control block (PCB)
- The kernel's record of one process, including its state and its saved registers.
Notes and sources
- 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.
- Real kernels have a few more states at the edges, such as a new process still being built and a zombie: a process that has exited but whose parent has not yet collected its exit status. The three in the middle are the ones the scheduler works with.
- A real read() only blocks when the data is not already in memory. If the kernel has the file cached, read() returns at once and the process stays running.
- When A woke, the kernel could have stopped B and run A at once. This lesson's simple scheduler does not: A waits in the ready queue. Which choice is better is a scheduling question.
- R. and A. Arpaci-Dusseau, Operating Systems: Three Easy Pieces, ch. 4: The Abstraction: The Process (4.4 Process States)
- R. and A. Arpaci-Dusseau, Operating Systems: Three Easy Pieces, ch. 6: Limited Direct Execution (the timer interrupt)
- Berkeley CS162, Lecture 3: Abstractions 1: Threads and Processes
- MIT 6.1810 (2024), lecture notes: Threads
- xv6-riscv source: kernel/proc.h (enum procstate)
- Linux man-pages: ps(1), process state codes
- Linux man-pages: read(2)
- Linux kernel documentation: CFS scheduler design
Quiz Unlocks after the last step.