OS resource management and processes
| English | Chinese | Pinyin |
|---|---|---|
| process | 进程 | jìn chéng |
| scheduler | 调度器 | diào dù qì |
| multi-tasking | 多任务 | duō rèn wù |
| spooling | 假脱机 | jiǎ tuō jī |
| caching | 缓存 | huǎn cún |
| round robin | 轮转 | lún zhuàn |
| context switch | 上下文切换 | shàng xià wén qiè huàn |
| process control block | 进程控制块 | jìn chéng kòng zhì kuài |
Why the mouse still moves when everything has frozen
- A program locks up. The window will not repaint, the spinner stops, nothing responds. Yet the mouse pointer still glides across the screen exactly as before.
- That is the operating system telling you something: the machine is not stuck, one process 进程 is. The scheduler is still handing out slices of the processor, and the frozen program is simply not doing anything useful with its.
- Every resource in the machine is shared this way: the processor by time, memory by space, the printer by a queue.
- This lesson is how an OS gets the most out of those resources, and how it manages a process from creation to termination.
Getting the most from the resources
- Multi-tasking 多任务: the processor is switched rapidly between processes, so several appear to run at once even though only one is executing at any instant.
- Paging: memory is moved between RAM and disk so more programs can be open than physical memory allows.
- Spooling 假脱机: output for a slow device is queued on disk, so the processor never waits for a printer. Caching 缓存 keeps recently used data in fast memory so it need not be fetched again.
- The OS also hides all of this behind a user interface, a command line or a GUI.
Multi-tasking lets several programs appear to run at once by:
The OS rapidly switches the single CPU between processes so they all seem to progress together.
Worked example: why spooling helps
- Explain how spooling improves the use of a computer's resources. [3]
- A printer is thousands of times slower than the processor, so a program sending output directly would wait for it and the processor would sit idle.
- With spooling the output is written quickly to a queue on disk, and the program continues immediately.
- A separate process then feeds the printer at its own speed, and several jobs can queue while the processor gets on with other work. Name the slow device, the queue, and what the processor does instead.
Spooling helps the system because:
Spooling buffers print jobs to disk so the fast CPU is not held up by the slow printer.
Which techniques help an OS get the most from its resources? Select all that apply.
Sharing time, queueing for slow devices and keeping hot data close. Killing waiting processes would lose the user's work, not improve utilisation.
Processes and the scheduler
- A process is a program in execution: its code, its current state, its memory and its open files. A program on disk is not a process; a program running is.
- The scheduler 调度器 decides which ready process runs next and for how long. Its goals are to keep the processor busy, respond quickly to interactive users, and be fair.
- Round robin 轮转 gives each ready process a fixed time slice and then sends it to the back of the queue: simple, fair and responsive. Other policies are first come first served, shortest job first and shortest remaining time.

Everyone gets a turn, and nobody keeps the processor
Round-robin scheduling gives each ready process a fixed time slice, then moves it to the back of the queue — making it fair and responsive.
Equal time slices in turn stop any one process hogging the CPU, so interactive programs stay responsive.
What is a process?
The file on disk is a program; once it is loaded and running, with state of its own, it is a process.
The process states
- New: being created. Ready: able to run, waiting only for the processor. Running: currently executing. Blocked: waiting for something else, usually input or output. Terminated: finished.
- The transitions are what the exam asks for. Running to ready when the time slice expires. Running to blocked when the process requests I/O. Blocked to ready when that I/O completes. Ready to running when the scheduler selects it.
- Note the asymmetry: a blocked process never goes straight back to running. It rejoins the ready queue and waits its turn.

Five states, and the reasons for each arrow
Match each process state to what it means.
A process cycles ready → running → (blocked) → ready, until it terminates.
Worked example: trace a process
- A process is running when it asks to read a file. Describe what happens to it.
- It moves from running to blocked, because it cannot continue until the data arrives, and the scheduler immediately gives the processor to another ready process rather than waiting.
- When the disk finishes, the process moves from blocked to ready. It does not resume immediately; it joins the ready queue.
- The scheduler later selects it, and it moves from ready to running, continuing from exactly where it stopped.
The life of a process
Tap round the loop a process travels. It only runs when the scheduler picks it; needing I/O sends it to blocked, and finishing its time slice sends it back to ready — round and round until it's done.
A running process asks to read a file. Put what happens to it in order.
A blocked process never returns straight to running: it rejoins the ready queue and waits its turn.
Context switching
- To change which process is running, the OS saves the current process's state, its registers, program counter and status, into its process control block 进程控制块, then loads the next process's state from that process's own block.
- That is a context switch 上下文切换. It has a real cost: during it the processor is doing housekeeping, not the user's work.
- So the time slice is a trade-off. Too long and interactive programs feel sluggish; too short and the machine spends its time switching instead of computing.
A context switch involves:
The OS saves the running process's registers/PC to its PCB and loads the next process's — a small overhead each switch.
During a context switch, a process's registers and program counter are saved into its ____.
The next process's state is then loaded from its own block. The saving and loading is real work, which is what makes switching cost time.
Interrupts and the kernel
- The kernel, the core of the OS, is what actually performs this: it responds to interrupts from devices and from programs, and an interrupt is what returns control to the OS from a running process.
- A timer interrupt at the end of a time slice is what makes pre-emptive scheduling possible at all; without it a program that never yields would keep the processor for ever.
- That is the answer to the opening puzzle: the frozen program holds no more of the processor than its slice, so the mouse keeps moving.
Marks that slip away
- A process is a program in execution, not the file on disk.
- Blocked to ready, never blocked straight to running. The scheduler chooses when it runs again.
- A context switch saves and restores state through the process control block, and it costs time.
- Multi-tasking means processes take turns so quickly they appear simultaneous, not that they truly execute at once on one core.
You've got it
- the OS maximises resource use by multi-tasking, paging, spooling to a disk queue and caching
- a process is a program in execution; the scheduler picks the next ready one, with round robin giving each a fixed time slice
- states new, ready, running, blocked, terminated: slice expiry sends running to ready, an I/O request sends it to blocked, and I/O completion sends it back to ready
- a context switch saves and restores state via the process control block and costs time, which is why the slice length is a trade-off