AQA 7517, section 4.6.1.4
The operating system (OS) sits between the hardware and the programs and users. It has two main roles that you need to know.
1. Hiding the complexity of the hardware
Hardware is complicated and varies a lot. Different hard disks, graphics cards and printers all work in different ways. If every programmer had to write code to control each of them, programs would be huge, difficult to write and would work on only some machines.
The OS hides these details. It provides a simple, consistent interface so that programs and users don't need to know how the hardware works. This is an example of abstraction.
- Device drivers are small programs that know how to control a particular device. The OS uses them, so programs can say "print this" or "save this file" without knowing how the actual printer or disk works.
- A program calls the OS using a standard application programming interface (API), for example "open a file", and the OS works out the details.
- The user interface (a desktop, icons, windows) hides the complex commands underneath.
- The file system presents storage as files and folders, hiding the sectors and tracks on the disk.
Because of this, the same program can run on many different computers with different hardware.
2. Resource management
A computer has limited resources, and many processes (running programs) want to use them at the same time. They compete. The OS manages the hardware, allocating processors, memory and I/O devices among the competing processes, so that all of them can work fairly and without interfering with each other.
Processor management
There may be many running processes, but a processor core can only do one job at a time. The OS decides which process gets the processor, and for how long. This is called scheduling.
One simple method is round robin: each process gets a short time slice, then the next process gets its turn, and so on in a circle. It happens so quickly that it looks like everything runs at once (multitasking).
| Process | Time slice 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Runs | A | B | C | A | B | C |
Memory management
The OS decides which parts of main memory each process can use. It:
- allocates memory to a process when it starts and takes it back when it ends;
- protects processes from each other, so one program can't overwrite another's data;
- uses virtual memory (part of the disk acts as extra RAM) when memory is full.
Managing I/O devices
The OS manages input and output devices such as keyboards, printers and disks. It:
- shares devices between processes (for example, a print queue so that two programs don't print on top of each other);
- uses buffers to hold data that is waiting to be sent or processed, so that fast processors don't wait on slow devices;
- handles interrupts from devices.
Other roles
- File management: organises, stores, names and protects files.
- Security: user accounts, passwords and file permissions.
- Providing a user interface.
- Running utilities and applications.
Worked example
Task: two programs are running and both want to print. Explain how the OS manages this.
The OS sees both processes competing for the one printer. Rather than letting them both send data at once (which would mix up the pages), it puts the print jobs in a queue and sends them one at a time. A printer driver converts the data into the form that this particular printer understands, which hides the printer's details from the programs. Meanwhile, the processor keeps both programs running by giving each one slices of time.
Exam tip: give the two roles clearly. (1) The OS hides the complexity of the hardware (using drivers and a simple interface), and (2) it manages resources, which means allocating the processor, memory and I/O devices among competing processes.
Check yourself
How does the OS hide the complexity of the hardware?
It gives programs and users a simple, consistent interface, using device drivers and a file system, so they don't have to know how the hardware works in detail.
Name the three resources that the OS allocates among competing processes
Processors, memories and I/O devices.
What is round robin scheduling?
Each process is given a short time slice of the processor in turn, cycling through all processes, so they all appear to run at the same time.
Why must the OS stop one program overwriting another program's memory?
To protect each program's data and keep the system stable. Otherwise a fault in one program could corrupt others or crash the whole computer.