Why a computer needs an operating system
Without an operating system, every app on a tablet would have to drive the screen, the disk and the network by itself. The operating system (OS) does that work once, for all of them. It is system software that controls the hardware and provides a platform on which application programs run.
Read the drawing from the top down: the user works with applications, the applications ask the OS, and only the OS works the hardware beneath it.
The purpose and what it allows
Picture one tablet running a game and a chat app at the same time. Each purpose of the OS lets the user or the apps do something: be able to name each one and say what it allows.
| OS purpose | What this lets the tablet do |
|---|---|
| Provides a user interface | lets its user communicate with the hardware through a GUI or command line |
| Provides a platform for applications | lets the game and chat app call OS services instead of driving devices themselves |
| Manages memory | keeps the data of both apps in RAM, protected from each other |
| Manages processes | shares processor time fairly, so both apps can make progress |
| Manages files and peripherals | lets the user save files and exchange data with devices |
1 Which two of these are system software: a compiler, a spreadsheet, a defragmenter, a game?
2 The chat app shows a photo by asking the OS to draw it, not by driving the screen itself. Which purpose of an OS is this?
3 Describe one task the OS does so that the game and the chat app can run at the same time.
- 1the compiler and the defragmenter (a translator and a utility)
- 2it provides a platform for applications: the app calls an OS service
- 3for example: memory management gives each app its own area of RAM and stops one reading the other’s; or process management gives each app turns on the processor
Memory and process management
A laptop can play music while you write an essay (multitasking), yet it has one RAM and one processor for every program to share. Memory management decides where each process is held in RAM; process management decides when each process uses the processor.
Memory management: where each process is held
Each row is the same 16 blocks of RAM at a different moment. Compare the two rows: B’s blocks are freed, D takes the first gap that fits, and the red line marks where A must stop.
- Allocates each process the blocks of RAM it needs, when it needs them
- Protects private memory: a process cannot access or overwrite another process's private area
- Takes blocks back when a process ends
- Moves data between RAM and disk as needed (virtual memory)
Process management: when each process runs
Read along the time arrow: the processor runs one process at a time, and each pause is the end of a time slice.
- Schedules: picks the next process to run, by priority
- Gives each process a time slice, pausing the others
- Moves processes between ready, running and waiting
- Shares out resources, settles clashes and lets processes exchange data
- Handles interrupts so a process can respond to an event
1 The OS takes back a program’s blocks of RAM when it closes. Is this memory management or process management?
2 In the second row of the memory figure, a new process E starts and needs 3 blocks. The OS gives it the first free blocks that fit. Which blocks does E get?
3 Why does “it allows multitasking” not describe a task of process management?
- 1memory management: it decides where processes are held
- 2blocks 13 to 15: block 10 is free but only one block long
- 3it is a result, not an action; a task says what the OS does, such as giving each process a time slice
File management and security management
A disk holds thousands of files, and the computer must find any one of them at once. File management organises how files are stored on, and found in, secondary storage. Not every user should reach every file: security management stops unauthorised access and makes it possible to recover lost data.
File management
Find essay.txt in the folder tree, then in the table: its letter E fills units 2, 3, 4 and 9, so one file can be split across the disk.
- Splits secondary storage into allocation units and records which units hold each file
- Builds and keeps the folder (directory) tree
- Sets the file system, e.g. FAT or NTFS
- Sets the rules for file names
- Controls who can open, edit or share a file
- Offers file operations: create, open, close, copy, move, rename, delete, search
Security management
Follow one request along the arrows: it is refused at the first check it fails, and only an allowed action reaches the log.
- Checks who is asking: authentication of users and processes
- Sets who may do what: access rights and permissions
- Provides for recovery of lost data
- Applies OS security updates as they are released
- Logs activity, so it can be checked later (auditing)
- Creates user accounts and passwords; runs a firewall and anti-malware
1 Use the file allocation table. Which allocation units hold photo.png?
2 essay.txt is deleted. Which units are now marked free?
3 A user signs in with the right password but has no permission to edit a file. At which step of the security figure is the edit refused?
- 15, 6, 7, 8
- 22, 3, 4, 9, 13, 14, 15: essay’s units go back to the free list
- 3access rights: authentication passed, but this user may not edit the file
Hardware management
A program that prints a page should not need to know how that printer works. Hardware management (input/output or peripheral management) lets programs use devices without knowing how each one works. Printing uses all three of its mechanisms: a driver, a buffer and an interrupt.
Follow the essay along the arrows: the driver turns it into printer commands, the buffer holds it while the slow printer works, and the interrupt asks for more.
What hardware management does
Without the OS, every program would have to handle each device’s speed, signals and power itself. Be able to give each task with its purpose: the task is what the OS does, the purpose is why.
| Hardware management task | Purpose |
|---|---|
| Loads the device driver for each device | the computer cannot talk to a device without its driver |
| Passes data between programs and devices | e.g. pages out to a printer, key presses in from a keyboard |
| Holds data in a buffer on the way | a keyboard, a disk and a printer each work at their own speed |
| Responds to interrupts (signals) from devices | a device reports that it is ready, finished or in trouble |
| Hides the differences between devices | a program prints the same way on any printer |
| Manages power | uses sleep states, processor throttling and battery controls to reduce power use |
Which management task is it?
| The OS… | Management task |
|---|---|
| stops the chat app reading the game’s part of RAM | memory management |
| starts the driver when a USB camera is plugged in | hardware management |
| confirms who a user is before letting them sign in | security management |
| decides whether the music or the virus scan gets the processor next | process management |
| records which disk units are still free | file management |
Which OS management task is each of these? The OS…
1 stops the chat app reading the game’s part of RAM.
2 starts the driver when a USB camera is plugged in.
3 confirms who a user is before letting them sign in.
4 decides whether the music or the virus scan gets the processor next.
5 records which disk units are still free.
6 Why does the OS hold the essay in a buffer on its way to the printer?
- 1memory management
- 2hardware management
- 3security management
- 4process management
- 5file management
- 6the printer works much more slowly than the processor; the data waits in the buffer, and the printer sends an interrupt when it needs more
Utility software
Like a car, a computer needs looking after, or it slows down and loses work. A utility program sets up, configures, analyses, optimises or maintains the computer. It is optional: the user or the OS starts it when a maintenance job needs doing.
Each utility at work
The strip on each card shows the disk or file before and after. Read it, then say what the utility does and why it is needed.
Disk formatter
Prepares a disk for use: checks it for errors and writes a new file system (directory and allocation table); can make partitions.
A disk cannot store files until it has a file system. Formatting erases the files on it.
Disk contents analysis / disk repair
Finds disk errors and marks bad sectors so they are skipped; recovers damaged files where it can.
Power loss or damage can corrupt files and spoil parts of the disk.
Defragmentation
Puts each file’s blocks into one contiguous run and joins the free space.
Files end up in fragments; the disk head must move between them, so reads are slower.
Virus checker
Scans files and memory for malicious code and removes it.
New viruses appear all the time, so it needs frequent updates and regular scans.
File compression
Reduces the size of a file. Text and program files need lossless compression, such as run-length encoding.
Saves storage space and cuts transmission time.
Back-up
Copies data on a schedule, without the user starting it.
If data is lost or damaged, the copy restores it.
Lossless compression: a sensor log
A weather station repeats the same reading. Run-length encoding (RLE) stores each run as its value once and the number of repeats:
Decoding restores all four readings, so no data is lost.
Do not confuse
A formatter prepares a disk and wipes it; disk repair fixes a disk already in use. A back-up is a copy kept in case the original is lost; it does not stop the loss.
1 Every night, a school’s files are copied to another drive without anyone starting the job. Which utility is this?
2 A sensor logs 21 21 21 21 21 19 19. Write the log in run-length encoding.
3 A student formats a USB drive that holds their coursework. What happens to the coursework?
- 1back-up: it copies data on a schedule
- 2(21, 5) (19, 2): each value once, with how many times it repeats
- 3it is erased: formatting writes a new, empty file system
Defragmentation and performance
A computer that opened files at once when it was new can feel slow a year later. Part of the reason is on its hard disk. Each file is stored in blocks, and as files are saved, deleted and extended, one file ends up in different places. The read-write head must move between them.
The same 16 blocks at three moments, top to bottom: after saving, after deleting and extending, then after defragmenting. Follow the orange arrow to see the extra trip the head makes for file A.
Why defragmenting makes files open faster
Each link leads to the next. An “explain” answer gives every link, ending at faster access.
Utilities that improve performance
Defragmenting is not the only utility that speeds a computer up. Two others help in different ways.
| Utility | How it improves performance |
|---|---|
| Defragmentation | each file is in one run, so the head moves less and files open sooner |
| Disk repair / contents analysis | bad sectors are marked and skipped, so data is not written to them |
| Virus checker | malware that runs in memory is removed, so more RAM is free for programs |
1 In row 2 of the figure, how many separate pieces (fragments) is file D in?
2 After defragmenting (row 3), which blocks hold file A?
3 Why does defragmenting a solid-state drive not make files open faster?
- 12: blocks 4–5 and block 9
- 2blocks 0 to 5, one contiguous run
- 3it has no read-write head to move, so joining the pieces saves no head movement
Program libraries
Why write a sort again when one is already written and tested? A program library is a set of pre-written (pre-tested, often pre-compiled) routines. A program imports the library, then calls its routines.
Follow each call along its arrow: the student’s program only names the routine; the code that runs is in the library.
Benefits of library routines: point, then because
Each benefit has its reason. In an answer, give the benefit, then the “because”.
| Benefit to the programmer | … because |
|---|---|
| Saves programming time | the routine already exists, so the programmer starts from it, not from nothing |
| Saves testing time; more robust | the routine has been tested and comes with documentation, so it is likely to work |
| Harder tasks are within reach | the programmer calls a routine they could not easily code themselves |
| Another language’s strengths | a routine written in a different language can use that language’s features |
| Shorter, more readable source | one call by name replaces the whole routine |
| Upgrades arrive | an improved routine is used by programs that link to it at run time (see DLLs) |
A library made by the team
- Team members call each other’s routines instead of rewriting them.
- A new program starts from routines already written: continuity from one program, and one programmer, to the next.
- Each member writes the routines they do best (their specialism); the others call them.
Drawbacks
- Compatibility: a routine written for another data format or language version fails when the program passes it different input.
- A routine that does nearly, but not exactly, the job must be edited, then tested again.
- A changed library routine can change a program’s results with no change to the program’s own code.
1 Give the two ideas that define a library routine.
2 A programmer calls SortList from the statistics library instead of writing a sort. Give one benefit, with its reason.
3 The library’s Average routine is changed. The student’s program now prints a different mean, though its own code is unchanged. Which drawback is this?
- 1it is pre-written (and pre-tested), and it is called from another program once the library is imported
- 2for example: it saves testing time, because the routine has already been tested; or it saves programming time, because the routine already exists
- 3a changed library routine can change a program’s results with no change to the program’s own code
Dynamic link libraries (DLL)
When two programs use the same library routine, each could carry its own copy. A dynamic link library (DLL) lets them share: it holds routines that are linked to a program when it runs, so several programs can use one copy instead of each holding its own.
Compare the two halves: in each, find the files on disk, then RAM with both programs running. Sharing one copy brings RAM down from 1200 KB to 1008 KB.
Benefits of DLL files: a benefit and why
Each saving in the figure is a benefit. Say what it saves, then why sharing one copy makes that happen.
| Benefit of a DLL | Expansion |
|---|---|
| The executable file is smaller | the routine lives in the DLL file, not in the program |
| Less main memory is used | one loaded copy of the DLL serves every program that needs it |
| No recompiling after a DLL change | a new version of the DLL drops in; the program is untouched |
| Upkeep sits elsewhere | the DLL’s author looks after it, not the programmer who calls it |
The drawback: dependence
The program depends on the DLL: if the DLL is missing, damaged or has a new bug, the program fails or gives wrong results.
1 Where is the filter routine kept when the programs use a DLL?
2 A third program C (400 KB) also uses the filters. All three run at once. How much RAM do they use with copied routines, and how much with the DLL?
3 The DLL file is deleted by mistake. What happens to programs A and B?
- 1in one DLL file; each program holds only a link to it
- 2copied: 300 + 500 + 400 + 3 × 200 = 1800 KB; DLL: 300 + 500 + 400 + 3 × 4 + 200 = 1412 KB
- 3they fail when they need the filters: each one depends on the DLL
Language translators
People write programs in words and symbols, but a processor executes only machine code. So source code must be translated first. An assembler translates assembly language; a compiler or an interpreter translates a high-level language.
Read each row along its arrows: what goes in, the translator, and what comes out. The note at the end of each row says what happens to an error.
What each translator does with an error
The two translators behave very differently when a program has a mistake in it. Give each one the same faulty program, and be able to say what it does.
1DECLARE Price, Total : INTEGER 2Total ← 0 3FOR Price ← 10 TO 30 STEP 10 4Total ← Total + Price 5OUTPUT "Total: ", Total 6NEXT Price 7OUPTUT "Final: ", Total
Compiler
Reads and checks all seven lines first, then reports the error in line 7 (with any others) in one list. No executable is produced, so nothing runs: there is no output.
Interpreter
Translates and runs lines 1 to 6 in turn, so this is output first:
Total: 30
Total: 60
It stops at line 7 and shows the error. Once it is corrected, it continues from line 7.
1 Which translator turns assembly language into machine code?
2 Line 3 is changed to FOR Price ← 10 TO 30 STEP 20; line 7 is still misspelt. What does the interpreter output before it stops?
3 What does the compiler output for that program, and why?
- 1an assembler
- 2Total: 10 then Total: 40: Price takes 10, then 30, and it stops at line 7
- 3nothing: it checks the whole program first, reports the error in line 7 and makes no executable
Compiler or interpreter?
While you write a program, you want to try each part as soon as it is typed. Once it is finished, you want one fast file to hand out. So an interpreter suits a program that is still being written, and a compiler suits one that is finished. Compare the two on the same aspect each time.
Benefits and drawbacks, point by point
Read across one row at a time: each row compares the two on one aspect, so you can set the two against each other.
| Interpreter | Compiler | |
|---|---|---|
| Finding errors | halts at the faulty line, so you see where it is; later lines are not reported, so no dependent errors | lists syntax errors after a full pass; one mistake can trigger false reports on later lines |
| Correcting errors | fix the line and carry on from it; each change shows its effect at once | fix, then compile the whole program again before it can run |
| Unfinished code | a half-written program can be run and tested | will not build while a syntax error remains |
| A large program | starts running at once, line by line | nothing runs until the whole compile has finished |
| Running again | each line is translated afresh on every run | the executable reruns with no translation, and faster |
| Giving it to users | users need the interpreter and the source code | users get an executable alone: no translator, and the source stays hidden, so users cannot read or change it |
Justify the choice for the stage
Naming a translator does not justify it. Link its feature to what the programmer needs at that stage.
A programmer is writing a revision quiz app for a school. Explain how the programmer uses an interpreter, and later a compiler, during its development.
- +1While the quiz is being written, use the interpreter
- +1… run and test each part as it is added, fixing each error where it halts
- +1Once the quiz is finished, use the compiler
- +1… it makes one executable file that reruns without retranslating and can be handed to the school without its source code
1 Which translator lets a half-written program be run and tested?
2 A games company sells its finished game and does not want players to read its code. Which translator should it use for the copy it sells? Give a reason.
3 A compiler reports errors on lines 8, 9 and 12. Only line 8 is wrong. Why are the others reported?
- 1an interpreter: it runs each line as it reaches it
- 2a compiler: players get an executable file only, so the source code stays hidden
- 3one mistake can trigger false reports on later lines that depend on it (dependent errors)
Partial compilation and interpretation
A games studio wants one game file that runs on Windows, Apple and Linux computers, each with a different processor. Java makes that possible because it is partially compiled and partially interpreted: the compiler produces bytecode, intermediate code that is not the machine code of any one processor.
Follow the bytecode: the developer compiles it once, then each platform’s own virtual machine turns it into machine code for its processor.
Why do it this way?
Each feature of the two-stage design solves a problem for the studio. Give the feature, then why it helps.
| Feature | Why it helps the developer |
|---|---|
| One intermediate bytecode file | each platform's virtual machine interprets it, so the same game can run on different platforms |
| Machine code made at run time | it can be optimised for the processor in use |
| Source compiled once | the source-to-bytecode translation is not repeated on each run, reducing translation work |
Four ways to translate, compared
The approach decides what you hand to the user and how quickly the program starts. Be able to say, for each approach, what it translates, when, and what a user needs to run the program.
| Approach | Translates | When | Needed to run the program |
|---|---|---|---|
| Assembler | assembly language → machine code | before running | the machine code only |
| Compiler | high-level → executable (object code) | before running, all at once | the executable only |
| Interpreter | high-level, line by line | while running | source code + interpreter |
| Partial (Java) | high-level → bytecode → machine code | compiled before; interpreted while running | bytecode + virtual machine |
Assembler
| Translates | assembly → machine code |
| When | before running |
| To run | machine code |
Compiler
| Translates | high-level → executable |
| When | whole program before running |
| To run | executable |
Interpreter
| Translates | high-level, line by line |
| When | while running |
| To run | source + interpreter |
Partial (Java)
| Translates | high-level → bytecode → machine code |
| When | compile before; interpret at run time |
| To run | bytecode + virtual machine |
1 What is bytecode?
2 Why can the same bytecode file run on a Windows laptop and on a Linux desktop?
3 What must a user have to run a Java game?
- 1intermediate code made by the compiler: not the machine code of any one processor
- 2each platform has its own virtual machine, which interprets the bytecode into that processor’s machine code
- 3the bytecode and a virtual machine for their platform
IDE features for writing code
Writing code in a plain text editor means hopping between separate tools to translate it, run it and fix it. An integrated development environment (IDE) brings together the tools to write, translate, run and debug a program in one application, and its editor helps while you type.
Match each numbered note to the editor window: every number names one feature you can see working on the code.
Features by purpose
Each feature helps with one job: writing the code, catching errors early or making it easy to read. Learn them in those three groups.
| Purpose | Feature | How it helps the programmer |
|---|---|---|
| Coding | Context-sensitive prompts | shows the words that can follow at this point, so there is less to type and remember |
| Auto-complete | finishes the word being typed | |
| Auto-correct | fixes a misspelt word | |
| Initial error detection | Dynamic syntax checks | marks a rule break in a line as soon as the line is entered |
| Presentation | Prettyprint | colours keywords, strings and comments differently, so the structure shows and slips stand out |
| Expand and collapse code blocks | folds away blocks not being worked on, so the overall shape is visible with less scrolling | |
| Auto-indentation | sets each block’s indent as it is typed, so the structure is clear |
1 Which feature underlines line 7 as soon as it is typed?
2 While line 10 is typed, the editor shows Total : INTEGER. Which feature is this, and how does it help?
3 THEN is added to line 7. The marks are 8, 9, 10, 11, 12. What is output?
- 1a dynamic syntax check
- 2a context-sensitive prompt: it suggests an identifier that fits at this point, so there is less to type and remember
- 3nothing: Total is 50, and 50 > 50 is false, so line 8 does not run
Debugging with an IDE
The hardest mistakes give no error message: a program can run and still output the wrong total. Debugging tools let you watch the program run, one line at a time, until the faulty line gives itself away.
Three debugging tools
Each tool shows a different part of the run, so you pick the one that answers your question. Be able to say what the programmer does with each one and what it shows.
| Tool | How the programmer uses it |
|---|---|
| Breakpoint | halts the program at a chosen line; the variables and the path taken so far can be inspected |
| Single stepping | runs one line, pauses and waits: read the values and see which line comes next, then step again |
| Report window | a watch window: lists variables and their values, arrays and expressions included, updated as each line runs |
Use the tools to find the wrong condition
The program should add five marks, 12 + 15 + 9 + 14 + 10 = 60, but it outputs 50. Use the tools in the numbered order to find out why.
1DECLARE Marks : ARRAY[1:5] OF INTEGER 2DECLARE Index, Total : INTEGER 3// Marks holds 12, 15, 9, 14, 10 4Total ← 0 5Index ← 1 6WHILE Index < 5 7Total ← Total + Marks[Index] 8Index ← Index + 1 9ENDWHILE 10OUTPUT "Total: ", Total
- 1Set the breakpoint before line 10, then run: inspect Index = 5 and Total = 50.
- 2Restart and single step the last loop test while watching Index: 5 < 5 is false, so the fifth mark is skipped.
- 3Change the condition to Index <= 5, rerun, and check that Total is 60.
Report window, single stepping through the loop
| Pass | Index | Marks[Index] | Total |
|---|---|---|---|
| 1 | 1 | 12 | 12 |
| 2 | 2 | 15 | 27 |
| 3 | 3 | 9 | 36 |
| 4 | 4 | 14 | 50 |
At the breakpoint (line 10)
Execution pauses before the output. The report window shows Index = 5, Total = 50: only four marks were added, so Marks[5] was never used. The condition should be Index <= 5; then the total is 60.
Watch the loop run, one line at a time
Follow Total and Index down their columns: the last mark goes missing at the final test. Each row is what the report window shows after one line runs, so be able to fill in a row like this.
| Line | Statement that runs | Total | Index | Output | Writes | What happens |
|---|---|---|---|---|---|---|
| 6 | WHILE Index < 5 | test 4 < 5 is true, so lines 7 and 8 run | ||||
| test 4 < 5 is true, so lines 7 and 8 run | ||||||
| 7 | Total ← Total + Marks[Index] | 50 | Total 50 | 36 + Marks[4] = 36 + 14 | ||
| 36 + Marks[4] = 36 + 14 | ||||||
| 8 | Index ← Index + 1 | 5 | Index 5 | 4 + 1 | ||
| 4 + 1 | ||||||
| 6 | WHILE Index < 5 | test 5 < 5 is false: the loop ends before Marks[5] is added | ||||
| test 5 < 5 is false: the loop ends before Marks[5] is added | ||||||
The whole run: one row each time round the loop
| Total | Index | Output | What decided it | |
|---|---|---|---|---|
| start | 0 | 1 | lines 4 and 5 set the starting values | |
| lines 4 and 5 set the starting values | ||||
| pass 1 | 12 | 2 | 1 < 5 is true: add Marks[1] = 12 | |
| 1 < 5 is true: add Marks[1] = 12 | ||||
| pass 2 | 27 | 3 | 2 < 5 is true: add Marks[2] = 15 | |
| 2 < 5 is true: add Marks[2] = 15 | ||||
| pass 3 | 36 | 4 | 3 < 5 is true: add Marks[3] = 9 | |
| 3 < 5 is true: add Marks[3] = 9 | ||||
| pass 4 | 50 | 5 | 4 < 5 is true: add Marks[4] = 14 | |
| 4 < 5 is true: add Marks[4] = 14 | ||||
| end | Total: 50 | 5 < 5 is false: the loop ends, so Marks[5] is never added | ||
| 5 < 5 is false: the loop ends, so Marks[5] is never added | ||||
1 Which tool pauses the program at one chosen line?
2 Marks holds 10, 10, 10, 10, 10. What does the faulty program output?
3 With the condition changed to Index <= 5, how many times does the loop run?
- 1a breakpoint
- 2Total: 40: only the first four marks are added
- 35 times: Index takes 1 to 5, and the test fails when Index is 6