AxoPrep

Computer Science

A1.3 Operating systems and control systems

What an operating system does, how it shares the CPU between processes and reacts to devices, and how control systems use sensors, actuators and feedback. Study guide, 1 practice questions with markschemes and 2 flashcards. Free.

role and functions of an operating system · scheduling approaches · polling versus interrupts · control systems with sensors, actuators and feedback · (HL) multitasking, resource allocation and memory management

Practise all 1 questions Study 2 flashcards

Study guide

Why an operating system?

An operating system (OS) sits between hardware and applications so programmers do not have to control the hardware directly. Its main jobs:

Scheduling

Only one process can use a core at a time, so the scheduler decides the order. Common approaches:

ApproachRuleStrengthWeakness
First come, first servedRun in arrival order to completionSimple, fair by orderShort jobs wait behind long ones
Shortest job firstRun the shortest remaining jobLowest average waiting timeLong jobs may starve; lengths must be known
Round robinEach process gets a fixed time slice, then goes to the backResponsive, nobody starvesFrequent switching costs time
PriorityHighest priority runs firstUrgent tasks served fastLow priority can starve (fix: ageing)

Worked round-robin trace: P1 needs 4 ms, P2 needs 6 ms, P3 needs 2 ms, slice 3 ms, queue order P1, P2, P3.

Time (ms)RunningRemaining after slice
0-3P1P1 = 1
3-6P2P2 = 3
6-8P3P3 = 0, finishes at 8
8-9P1P1 = 0, finishes at 9
9-12P2P2 = 0, finishes at 12

A process that needs less than a full slice gives up the CPU early, so the next one starts sooner.

Polling versus interrupts

flowchart TD
  A[CPU running a program] --> B{Interrupt pending at end of instruction?}
  B -- No --> A
  B -- Yes --> C[Save registers and PC on the stack]
  C --> D[Run the interrupt service routine]
  D --> E[Restore registers and PC]
  E --> A

Keyboards and network cards normally use interrupts because key presses are unpredictable and rare compared with CPU speed. Polling suits a sensor that must be read at a steady rate anyway, or simple embedded devices.

Control systems

A control system keeps a physical quantity at a target value.

TARGET = 21.0
while True:
    temp = read_sensor()
    if temp < TARGET - 0.5:
        heater_on()
    elif temp > TARGET + 0.5:
        heater_off()
    wait(5)  # seconds

The 0.5 margin stops the heater flicking on and off constantly. An open-loop system (a basic toaster timer) has no feedback; a closed-loop system does.

Multitasking, resources and memory (HL)

Common mistakes

Exam tips

Cheat sheet

Key definitions

Operating system

System software that manages hardware resources and provides services and an interface for applications and users.

Scheduler

The part of the OS that decides which ready process uses the CPU next and for how long.

Time slice (quantum)

The fixed amount of CPU time a process receives in round-robin scheduling before being moved to the back of the queue.

Polling

Repeatedly checking the status of a device to see whether it needs attention.

Interrupt

A signal to the CPU that an event needs immediate attention, causing it to pause the current task and run a service routine.

Sensor

An input device that measures a physical quantity in the environment.

Actuator

An output device that produces physical movement or change in response to a control signal.

Feedback

Using the output of a system to adjust its next input so the system stays near a target value.

Context switch (HL)

Saving the state of a running process and loading the state of another so the CPU can change task.

Virtual memory (HL)

Using part of secondary storage as an extension of RAM, with pages moved between the two as needed.

Practice questions

SLPaper 1Standard

Question 1

(a) [3]

Three processes arrive at the same time: P1 needs 5 ms, P2 needs 3 ms, P3 needs 1 ms. The OS uses round-robin scheduling with a time slice of 2 ms, in the order P1, P2, P3. Determine the time at which each process finishes.

Markscheme
  • 1 Order of slices: P1 (0–2), P2 (2–4), P3 (4–5)
  • 1 Then P1 (5–7), P2 (7–8), P1 (8–9)
  • 1 P3 finishes at 5 ms, P2 at 8 ms, P1 at 9 ms
(b) [3]

Explain why a keyboard is usually handled with interrupts rather than polling.

Markscheme
  • 1 Key presses are infrequent and unpredictable
  • 1 Polling wastes CPU time repeatedly checking when nothing has happened
  • 1 An interrupt lets the CPU do other work and respond only when a key is actually pressed

Key facts

Polling vs interrupts

Polling: CPU repeatedly checks a device (wastes time if events are rare). Interrupt: device signals the CPU only when it needs attention.

Round-robin scheduling

Each process gets a fixed time slice in turn; unfinished processes go to the back of the queue.