Cambridge AS & A Level · Part 1 · Chapter 8
System Software
The software that sits between you and the hardware: the operating system, the utilities that keep a disk healthy, the libraries programs borrow from, the translators that turn code into something a processor can run, and the IDE you write it in. Every question and exam question from the chapter is here, with labs to try each idea.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- explain why a computer system needs an operating system (OS)
- explain the main management tasks the OS carries out
- show you understand why an OS comes with utility software
- Show you understand program libraries
- show you understand why we need an assembler for assembly language, a compiler to translate a high-level language program, and an interpreter to translate and run one
- explain the benefits and drawbacks of a compiler and of an interpreter, and justify when to use each
- show awareness that some high-level languages, such as Java, are partly compiled and partly interpreted
- describe the features of a typical Integrated Development Environment (IDE).
8.01 System software
Picture using a computer in the 1960s. A typical session went something like this:
- Walk into the machine room carrying a deck of punched cards (your program) and a reel of punched paper tape (your data).
- Switch the computer on.
- Load the card deck into the card reader and press its button.
- Load the paper tape into the tape reader and press its button.
- Press a button to run the program now in memory, using the data now in memory.
- Press a button to send the output to the line printer.
- Switch the computer off.
- Walk out with your cards, your tape and the printout.
Every step was a person pressing a button to drive the hardware directly. Imagine how many buttons a modern computer would need if it still worked like that!
What that machine lacked was an operating system: software that controls the hardware and talks to the application programs. An OS is one kind of system software, whose job is to help the computer itself run. Application software, by contrast, is written to do a particular job for the user, such as editing a photo or keeping accounts.
8.02 Operating system activities
There is no single agreed list of what an OS does, and the tasks overlap. One sensible way to group them:
🧑💻 User–system interface
The OS must give the user a way to control the computer. It can be a command-line interface, where the user types instructions, or a graphical user interface (GUI) with windows, icons, menus and a pointer. Either way, the OS turns what the user does into actions.
🔌 Program–hardware interface
Programmers write programs without knowing the exact hardware they will run on. The OS sits in between: a program asks the OS for a service (read a file, draw on the screen) and the OS deals with the particular hardware.
⚙️ Resource management
Many programs run "at the same time", so the OS shares out the processor and the other resources between them. Each running program is a process. The OS schedules processes so they take turns on the processor, and it settles conflicts when two processes want the same resource, such as the printer.
🧠 Memory management
- Memory protection: stops one process reading or overwriting memory another process is using.
- Memory organisation: decides how processes are placed in memory. Virtual memory using paging or segmentation lets more be loaded than physical memory can hold (more in Chapter 20).
- Memory optimisation: tracks which areas are free and which are in use, and decides which processes are in memory now.
🖨️ Device management
Each device needs a device driver, software that lets the OS control it. The OS also decides which process may use a device and when.
🗂️ File management
The OS provides file naming conventions, a directory (folder) structure so files can be organised and found, and access control, so only users with permission can read or change a file.
🔒 Security management
The OS helps recover data after it is lost, prevents intrusion by unauthorised users, and keeps data private. You will meet these again in Chapters 9 and 21.
🚑 Error detection and recovery
Errors can come from the software or the hardware. The OS must be able to stop a process that has gone wrong, run diagnostics to find the cause, and, in the worst case, shut the system down in an orderly way so no data is lost.
Assisting the user: user–system interface, file management (names, folders), security management (privacy, recovery after loss).
Running the system: program–hardware interface, resource management and scheduling, memory management, device management, error detection and recovery.
The problem: many tasks do both. File access control protects the user's privacy but also protects system files. Error recovery keeps the system alive but its real purpose is to save the user's work. So the two groups overlap, which is exactly the point of Task 8.01.
🧪 Lab · Which OS task is this?
Each card describes something the OS is doing. Choose the management area it belongs to.
8.03 Utility software
An OS ships with utility programs. They are not part of the OS's normal running; the user (or a schedule) runs one when it is needed, to look after the computer.
💿 Hard disk formatter
A formatter gets a disk ready for use. It:
- Wipes any data already on the disk
- sets up the file system, including the table of contents that lets the OS find a file and its sectors
- can split the physical disk into separate partitions, each acting as its own logical drive.
🩺 Disk contents analysis and repair
Often part of the formatter, this utility checks the disk for errors. A bad sector is a physical fault, either from manufacture or from mishandling, for example moving a computer without first parking the heads away from the platter. Other errors follow a power cut or a sudden shutdown, leaving some files unusable. The repair utility marks bad sectors so the file system never uses them again. If a file is damaged it tries to recover what it can; otherwise it has to delete the file.
🧩 Hard disk defragmenter
Even a perfectly healthy disk gets slower over time. Files are created, edited and deleted, and because a file is stored in sectors (Chapter 3), its pieces end up scattered. The OS does not tidy up after every change, because that would waste too much processor time. Figure 8.01 in the book shows how it happens; step through it below.
🧪 Lab · Figure 8.01, step by step
Twelve sectors of a disk. A half-filled square is a sector that is only partly used.
🧪 Lab · Count the fragments, then defragment
A random disk after months of use. How many separate fragments (runs of neighbouring sectors) does the named file have? Each fragment means one more head movement to read it.
A defragmenter reorganises the disk so each file sits in neighbouring sectors, and the free space is in one block. Reading a file then needs far fewer head movements. It takes a long time to run, and it cannot work at all if the disk is too full, because it needs free space to shuffle files into.
💾 Backup software
You could back up by copying files by hand, but a backup utility does it better. It can run on a schedule, so nobody has to remember, and it can copy only the files that have changed since the last backup, which saves time and space.
- How often backups run (daily, weekly) and whether they are full or only changed files (incremental).
- Where they go: an external hard disk, a NAS box on the network, tape, or cloud storage.
- How many generations are kept, and whether a copy is stored off-site.
- Whether anyone has ever tested a restore. A backup you cannot restore is no backup.
🗜️ File compression
Compression utilities make files smaller to save storage, but they matter most when a file is sent over a network. Zip a large attachment before emailing it, for example. (Compression itself is covered in Chapter 1, Section 1.07.)
🛡️ Virus checker
A virus checker is really a utility that should be running all the time, not just when needed. It must be updated regularly to know about new threats, and it should routinely scan every file on the system as well as checking new files as they arrive.
🧪 Lab · Which utility do you need?
Read the situation and choose the utility that fixes it.
8.04 Program libraries
Why write a subroutine that someone has already written and tested? Programmers reuse code from program libraries: collections of subroutines that are known to work. This saves development time and makes the program more reliable.
You already use one kind every day: the built-in functions of your programming language (Chapter 14, Section 14.07). A famous bigger example is the NAG library, more than 1600 numerical and statistical routines first released in 1971 and still sold today.
A compiler turns the source code into object code. Before that object code can run, it has to be linked with the library subroutines it calls, then loaded into memory. There are two ways to do the linking.
📦 Static linking
A copy of each library routine is joined into the program's executable file. Every program gets its own copy, so the executable is bigger, and if several programs run at once there are several copies of the same routine in memory.
🔗 Dynamic link library (DLL)
The executable holds only a small stub. When the program runs, the stub links to the library file, which is loaded once and shared by every process that needs it. Executables are smaller, less memory is used, and fixing or upgrading the DLL upgrades every program that uses it, automatically.
The drawback of a DLL is that the program now depends on something outside itself. If the DLL is missing, the wrong version, corrupted or has a new bug, the program fails, and because the fault is not in the program's own code it can be very hard to diagnose.
🧪 Lab · Static linking vs DLL
Each program's own code is 200 KB. They all call the same 400 KB graphics library. A DLL stub is 5 KB.
📦 Static
🔗 DLL
🧪 Lab · Static or DLL?
8.05 Language translators
A processor can only run machine code, so any other program needs a translator. A program in assembly language is translated by an assembler (covered in Chapter 6). A program in a high-level language is translated either by a compiler or by an interpreter, and the two work very differently.
🗣️ Interpreter
- The interpreter, the source code and the program's data are all available.
- The interpreter reads one line of source code…
- …and analyses it.
- If the line has an error, it reports it and stops.
- If not, it converts the line to intermediate code…
- …and executes it straight away.
- Go back to step 2 for the next line,
- until the program ends.
🏭 Compiler
- The compiler and the source code are available; no data is needed yet.
- The compiler reads one line of source code…
- …and analyses it.
- If the line has an error, it records it and carries on.
- If not, it converts the line to intermediate code.
- Go back to step 2 until every line is done.
- No errors: it produces object code.
- Any errors: it prints the error list and produces no object code.
With a compiler, the object code can be run immediately, or later, as many times as you like, without the compiler being present.
🧪 Lab · Translate it two ways
Each new program has random values and may contain zero, one or two errors. Predict, then step through it.
Translator
Program output
⚖️ Compiler or interpreter?
For the programmer
- An interpreter stops at an error the moment it reaches it, so you see it at once and can fix it in context.
- But code that has not been executed has not been checked: a syntax error in a rarely-run branch can sit there unnoticed.
- To share an interpreted program you must hand over the source code, which others can read and copy.
- A compiler lets you hand over just an executable, so the source code stays private.
For the user
- An interpreted program needs the interpreter and the source code every time it runs, and it is translated again on every run.
- A compiled program needs only the object code, and it runs faster because the translation is already done.
- But object code cannot be inspected, so a user has to trust that it does not hide something malicious, such as a virus.
Whichever is used, the translator has to be written for the processor the program will run on.
| Interpreter | Compiler | |
|---|---|---|
| When errors appear | One at a time, as the line is reached | All together, at the end of compilation |
| What is distributed | Source code (plus interpreter) | Executable object code only |
| Speed of execution | Slower: translated on every run | Faster: translated once |
| Best stage to use it | Development and debugging | Finished, near error-free program |
Justifying the choice
During development, use an interpreter. One error often triggers others, so finding it early and fixing it straight away saves time, and interpreters usually come with debugging tools. Once the program is (nearly) error-free, compile it. You get an executable that can be distributed, keeps the source private, and runs faster.
☕ Partly compiled, partly interpreted: Java
Java tries to get the best of both. The source code is compiled once into Java Byte Code. Every type of computer has its own Java Virtual Machine (JVM), which interprets the byte code. So the same byte code runs on any machine that has a JVM: it is portable.
🧪 Lab · Compiler or interpreter?
8.06 Features of an IDE
An Integrated Development Environment brings an editor, a translator and debugging tools together in one program. The examples below come from Python's IDLE and Visual Studio.
🎨 Prettyprint
Prettyprinting lays code out so it is easy to read. Different kinds of word get different colours: keywords, built-in functions, comments, strings and the name in a function header. The editor also indents code automatically after a line that opens a block. In IDLE, for example, typing a colon at the end of a def or for line makes the next line start indented.
💬 Context-sensitive prompts
As you type, the editor suggests what could come next, based on where you are: the methods of an object after a dot, the parameters a function expects, or the identifiers you have already declared. You pick one instead of typing it, which is quicker and avoids spelling mistakes.
⚠️ Dynamic syntax checks
The editor checks syntax while you type, not just when you run. An error is underlined straight away, and pointing at it shows a message. In Figure 8.04, the line Const Space := " " is underlined because Visual Basic uses =, not :=, so it reports "End of statement expected."
➕ Expanding and collapsing code blocks
A small + or − in the margin next to a function, loop or class lets you hide its body. Collapsing the parts you are not working on makes a long program much easier to navigate.
🐞 Debugging
A breakpoint marks a line where the program will pause when it reaches it. You can then step through one line at a time and look at a variable watch window that shows every variable's current value. In Figure 8.05 the breakpoint is on the while line (line 4). The program has paused there after one pass through the loop, and IDLE's Debug Control window lists the local variables: NewNumber 8, Numbers 1, Total 8.
🧪 Lab · A mini IDE
This is the Figure 8.05 program with a comment added as line 1, so the while is line 5. Tap a line number to set a breakpoint, tap ▾ to collapse the loop, then Run or Step and watch the variables change.
This is the program exactly as in Figure 8.05. Run it with the watch open: is Total what you expect?
Variable watch
Console
Predict first
🧪 Lab · The editor that helps as you type
Type a line of Python. Suggestions appear as you type (context-sensitive prompts: tap one to accept it), and the line is checked as you go (dynamic syntax check). Try while Total = 10 or print("hi".
🧪 Lab · Name the IDE feature
📌 Summary
- The tasks an operating system carries out can be grouped in more than one way.
- Utility programs such as a disk formatter, disk repair, defragmenter, backup, compression and virus checker come with an OS.
- Library programs, including DLLs, save time and are reliable because they have already been tested.
- A high-level language program is translated by an interpreter or a compiler.
- Java is compiled to byte code, which a Java Virtual Machine interprets.
- An IDE provides features such as prettyprint, context-sensitive prompts, dynamic syntax checks, collapsing blocks and debugging tools.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my mark-scheme-style points, not official mark schemes.
(i) Command-line interface; graphical user interface (GUI).
(ii) Command line: keyboard. GUI: mouse (or touch screen, touchpad).
Any three, each named and explained (2 marks each):
- Memory management: allocates memory to processes, protects each process's memory from the others, and can use virtual memory (paging/segmentation).
- Resource / process management: schedules processes so they share the processor, and resolves conflicts when two want the same resource.
- File management: naming conventions, a directory structure and access control so files can be stored, found and protected.
- Device management: installs and uses device drivers and controls which process may use each device.
- Security management: user accounts and passwords to stop intrusion, privacy of data, recovery after data loss.
- Error detection and recovery: stops a failing process, runs diagnostics, and shuts down safely without losing data.
(i) Disk analysis/repair utility; defragmenter. (A formatter also scores.)
(ii)
- Repair: needed because the disk may have bad sectors (manufacture fault, mishandling) or damaged files after a power cut. It scans the disk, marks bad sectors so they are never used, and recovers what it can from damaged files, deleting them otherwise.
- Defragmenter: needed because creating, editing and deleting files scatters them across the disk, so reading a file needs many head movements and is slow. It rearranges the sectors so each file is contiguous and free space is in one block.
- Formatter (last resort): wipes the disk and rebuilds the file system and partitions.
(iii) Any two of: backup utility, file compression, virus checker.
(i) Any three: the code is already written, so development is quicker; it has been tested, so it is reliable; it may be written by experts, e.g. complex maths; the programmer does not need to know how it works, only how to call it; the same routines can be shared across many programs.
(ii) Any two: a language's built-in functions (e.g. len, random, sqrt); a maths/statistics library such as NAG; a graphics library; a DLL providing file dialogs or printing.
An assembler translates assembly language (a low-level language, mostly one-to-one with machine code), whereas a compiler or interpreter translates a high-level language.
(i) Any three:
- A compiler translates the whole program before any of it runs; an interpreter translates and executes one line at a time.
- A compiler produces object code; an interpreter does not.
- A compiler reports all errors at the end; an interpreter stops at the first error it reaches.
- An interpreter needs the program's data during translation; a compiler does not.
- An interpreted program is translated again every time it runs.
(ii) Advantages: an error is found as soon as its line is reached, so it can be fixed straight away; partly-written programs can be tested; good debugging support. Disadvantages: runs slower because it is retranslated every time; the interpreter must be present; the source must be distributed so others can copy it; lines never executed are never checked.
(iii) Java is compiled to byte code, which is then interpreted by a Java Virtual Machine on the target computer (so it is portable).
- Prettyprinting: displays code with colour-coding for keywords, strings, comments and so on, and with automatic indentation, so it is easier to read.
- Context-sensitive prompt: as you type, the editor offers a list of what can validly come next (identifiers, methods, parameters), which you can pick from.
- Dynamic syntax check: the syntax of each line is checked as it is typed, and errors are highlighted (e.g. underlined) immediately, before the program is run.
- Debugging: finding and correcting errors in a program, supported by tools such as breakpoints, single stepping and variable watches.
- Breakpoints: the program pauses when it reaches a chosen line.
- Single stepping: execute one line at a time to follow the path through the code.
- Variable watch / report window: shows the current value of each variable while paused.
- The values can be checked against a trace table or expected values to find where the logic goes wrong.
- Formatting sets up the file system / directory (table of contents) so the OS can store files and find them again.
- It organises the disk into tracks and sectors, and can split it into partitions (logical drives).
- Defragmenter: files become split across non-adjacent sectors; it rearranges them to be contiguous so access is faster.
- Disk repair: finds and marks bad sectors and recovers damaged files.
- Backup: copies files (on a schedule, only changed files) so they can be restored if the originals are lost.
- File compression: reduces file size to save storage and transmission time.
- Virus checker: detects and removes malware, scanning files routinely and as they arrive.
Cambridge International AS & A Level Computer Science 9608, Paper 12 Q10, November 2015
- Saves time: the routine is already written, so the programmer does not have to write it again.
- Reliable: it has already been tested and used many times, so it is unlikely to contain errors.
- Expertise: it may do something the programmer could not easily write, such as complex maths or graphics.
(i) Any two, each explained:
- The executable is smaller, because it holds only a stub, not the routine itself.
- Only one copy of the DLL is loaded into memory and shared by all the processes using it, so less memory is used.
- If the DLL is updated, every program using it gets the improvement without being recompiled.
(ii) The program depends on an external file: if the DLL is missing, is the wrong version or is corrupted, the program will not run (or misbehaves), and the cause is hard to find because it is outside the program.
Cambridge International AS & A Level Computer Science 9608, Paper 12 Q8, November 2016
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 8 System Software · Figures from the Cambridge coursebook (Langfield & Duddell)