Operating systems and utilities

What an operating system does, scheduling, and utility software.

F9.9Logic and computer systemsGCSE15 min

Covers OCR J277 1.5.1 Operating systems · OCR J277 1.5.2 Utility software · AQA 8525 3.4.3 Software classification · Edexcel 1CP2 3.2.1 Operating systems · Edexcel 1CP2 3.2.2 Utility software

Do this lesson in the simulator

When you run a program, you never tell the processor which memory to use, how to talk to the camera, or how to share time with the other programs running. The operating system does all of that. This lesson looks at what an operating system does, then at utility software, the programs that keep a computer running well.

What an operating system does

The operating system (OS), such as Windows, macOS, Android, or Linux, is system software that manages the computer's hardware and runs the other programs. Its main jobs:

Job What it means
User interface lets the user control the computer: a graphical interface with windows and icons, a command line, or a touch screen
Memory management decides which programs and data go where in RAM, keeps programs from using each other's memory, and moves data to virtual memory when RAM is full
Multitasking shares the processor between the running programs, switching between them so quickly they seem to run at once
Peripheral management and drivers talks to devices such as printers, cameras and keyboards through device drivers, small programs that translate between the OS and each device
User management user accounts, passwords, and who is allowed to use which files
File management organises files into folders, names them, and lets them be moved, copied and deleted
Layers: programs at the top, the operating system below them, then device drivers, then the hardwarebrowsergameyour programoperating systemuser interfacememorymultitaskingfilesusersprocessormemorystoragecamera, printerdevice drivers
Programs never reach the hardware themselves. They ask the operating system, which shares out the processor and memory, keeps the files, and talks to each device through its driver.

Firmware for ESP32 chips like BugBot's is usually built on FreeRTOS, a small real-time operating system. It has no windows or user accounts, but it still shares the processor between tasks: the motor loop, the camera, the Wi-Fi link, and your program.

Sharing the processor

A single core can only run one instruction at a time. To multitask, the OS gives each program a short time slice, then switches to the next. Taking turns like this is called round robin scheduling:

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

jobs = {"music": 3, "browser": 5, "download": 2}     # time slices each still needs
queue = list(jobs)
clock_tick = 0
while queue:
    name = queue.pop(0)
    jobs[name] = jobs[name] - 1
    clock_tick = clock_tick + 1
    print(f"tick {clock_tick}: {name}")
    if jobs[name] > 0:
        queue.append(name)       # not finished: back of the queue
    else:
        print(f"  {name} finished")

Run this in the simulator

A timeline of the lesson's round robin: ten ticks, the three jobs taking turns one slice at a time12345678910tickmusic (3)donebrowser (5)donedownload (2)doneeach box is one time slice; the shaded box is the job's last
The lesson's three jobs, in the order its code runs them. Each takes one slice and goes to the back of the queue, so the short download is done at tick 6 while the browser, which needs 5 slices, runs on alone at the end and finishes at tick 10.

Utility software

Utility software is system software that helps to maintain, protect or tidy the computer. The ones on the exam:

  • Defragmentation: on a hard disk, files end up split into pieces scattered across the disk, which slows reading because the head has to move around. A defragmenter moves the pieces of each file back together, and free space together. SSDs should not be defragmented: they have no moving head to benefit, and the extra writes wear them out.
  • Compression: makes files smaller to save storage space or send them faster, as in lesson F8.9.
  • Encryption: scrambles files so only someone with the key can read them, which module F11 covers.
  • Backup: copies files to another place so they can be restored if the originals are lost. A full backup copies everything; an incremental backup copies only what has changed since the last backup, which is faster but needs every backup to restore.
  • Antivirus / anti-malware: scans for and removes malicious software.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# a disk with files split into pieces: each letter is a block of that file, . is free
disk = "AAB.C.BBA..CA.B"
print("before:", disk)
tidy = "".join(sorted(ch for ch in disk if ch != ".")) + "." * disk.count(".")
print("after: ", tidy)

Run this in the simulator

The lesson's disk as fifteen blocks, before and after defragmenting, with the pieces of file A markedbeforeAABCBBACABpieces: A 3, B 3, C 2afterAAAABBBBCCpieces: A 1, B 1, C 1
The lesson's disk, with file A shaded. Before, A is in 3 pieces, so the head has to jump 2 times to read it. After defragmenting, every file is in one piece and all the free space is together at the end.

Task: a round-robin scheduler

Write a round-robin scheduler with a time slice of 2 units. Each job in jobs needs some units of processor time. Take the job at the front of the queue, run it for 2 units or for what it has left, whichever is less, and print <name> ran for <n>. If it is not finished, put it at the back of the queue; if it is, print <name> finished at <t>, where t is the total time so far.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

jobs = [("motors", 3), ("camera", 5), ("radio", 2)]
time_slice = 2

Challenges

  1. Try a time slice of 1 and of 10. Which is fairest? Which switches least?
  2. Give each job a priority and always run the highest priority job that is waiting.
  3. Make an incremental backup: given yesterday's files and today's, print only the files that are new or changed.