CIE AS & A Level Computer Science, section 16.1 (Purposes of an Operating System (OS))
Process and multitasking
A process is a program being executed. With multitasking the OS switches the processor between processes so that many seem to run at once. The scheduler decides which process runs next.
Process states
| State | Meaning |
|---|---|
| Running | using the processor |
| Ready | able to run, waiting for the processor |
| Blocked | waiting for an event such as input or a disk read |
Transitions: ready to running (scheduler selects it), running to ready (time slice ends or higher priority arrives), running to blocked (waits for I/O), blocked to ready (I/O completes).
Process control block (PCB)
When a process is switched out, its details are stored in a PCB: process ID, state, program counter, register contents, priority and memory information, so it can resume from the same place.
Scheduling algorithms
| Algorithm | How it chooses |
|---|---|
| First come first served | in order of arrival |
| Shortest job first | the process with the shortest burst time |
| Shortest remaining time first | the one with the least time left (pre-emptive) |
| Round robin | each process gets a fixed time slice, then goes to the back of the queue |
| Priority | the highest priority first |
Worked example: round robin
Processes P1 (5 units), P2 (3 units) and P3 (4 units) arrive together. Time slice is 2.
Order: P1 (0-2), P2 (2-4), P3 (4-6), P1 (6-8), P2 (8-9), P3 (9-11), P1 (11-12).
P2 finishes at 9, P3 at 11, P1 at 12.
Interrupts
An interrupt is a signal that makes the processor stop the current process, save its state and run an interrupt service routine, then restore the state.
Pre-emptive and non-pre-emptive
A pre-emptive scheduler can take the processor away from a running process (round robin, priority). A non-pre-emptive one lets it run until it finishes or blocks.
Common mistake: saying a process is "blocked" because it is waiting for the processor. That is ready. Blocked means waiting for an event, such as input. Also, round robin is fair but has context-switch overhead.
Exam tip: for a scheduling question, draw the order of execution with the time at each switch, then read off finish times. Name the state and the event for each transition.
Check yourself
What state is a process in while waiting for a disk read?
Blocked.
What is stored in a process control block?
The process ID, state, program counter, register values, priority and memory details, so it can be resumed.
Give one advantage of round robin scheduling.
Every process gets a fair share of processor time, so none is starved.