Part 8 of 8 · 3 min read
Exercises
Easy
Easy 1: One sentence (20 minutes)
Write the definition of an operating system in your own words in one sentence, and name its three jobs.
Done when: a sentence plus three jobs (virtualise, manage resources, provide an interface).
Hint
The three jobs are virtualisation, resource management and a system-call interface.
Easy 2: Sort the examples (20 minutes)
Sort these into mechanism or policy: "switch the CPU to another program", "pick the shortest job first", "save the registers of the old program", "evict the least recently used page".
Done when: two mechanisms (the first and third) and two policies (the second and fourth).
Hint
A mechanism says how, a policy says which.
Easy 3: CPU use (20 minutes)
Each program waits 60 per cent of the time (p = 0.6). Give the CPU utilisation for n = 1, 2 and 3.
Done when: you write 40 per cent, 64 per cent and 78.4 per cent.
Hint
Compute 1 − 0.6, 1 − 0.36 and 1 − 0.216.
Medium
Medium 1: How many programs? (30 minutes)
With p = 0.9, find the smallest n that gives at least 60 per cent CPU use. Show the table up to that n.
Done when: you find n = 9 (1 − 0.9^9 = 0.613) and show that n = 8 gives 0.570.
Hint
Compute 0.9 raised to 8 and to 9.
Medium 2: Run the demo (30 minutes)
Compile the cpu.c program and run it alone, then four copies together. Record the real time and the order of labels for three runs.
Done when: a table of three runs with the order of labels each time, and a sentence on why they differ.
Hint
Use time and run the four copies in the background with & and wait.
Medium 3: Goals in tension (30 minutes)
Pick two design goals from section 5 that conflict and give one real feature where the conflict shows up.
Done when: a named pair of goals and a concrete feature, such as memory protection checks and speed.
Hint
Think of what a safety check costs in speed.
Hard
Hard 1: Two resources (60 minutes)
Describe how the OS virtualises memory and a disk in a few paragraphs. For each, say what the program sees and what really exists.
Done when: two descriptions, each with "program sees" and "reality" lines.
Hint
Programs see a private flat range of addresses and a tree of files.
Hard 2: Improve the model (60 minutes)
The formula 1 − p^n ignores the cost of switching programs. Suppose each extra program wastes 4 per cent of the CPU on switching. Write a revised formula for CPU use and find the n from 1 to 10 that gives the highest use at p = 0.8.
Done when: a formula such as (1 − p^n) × (1 − 0.04(n − 1)), a table for n = 1 to 10, and the best n (here 7, at about 0.60).
Hint
Multiply the original formula by the share of CPU not lost to switching.
Hard 3: Design for a phone (60 minutes)
Rank the five design goals for a smartwatch and for a database server. Explain the largest difference between the two rankings.
Done when: two ranked lists and a paragraph naming one goal that moves up or down.
Hint
A watch cares most about energy, a server about reliability and speed.