OS function: managing multitasking

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

OS function: managing multitasking

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How does a single-core CPU make several programs appear to run at the same time?
A The OS shares CPU time between programs in very short slices
B The CPU runs every program fully at the exact same instant
2. Which OS function lets you listen to music while typing an essay and downloading a file?
A Managing multitasking
B Managing user accounts
3. What does the OS do when a program's time slice ends?
A It switches the CPU to another program
B It closes the program permanently
4. How long is each slice of CPU time a program gets?
A Several minutes, until the program is finished
B Very short, so switching looks instant to the user
5. Why must the OS keep each program's work separate during multitasking?
A So only one program can be stored in RAM
B So one program's data does not overwrite or mix with another's

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1time_slice = 10 # milliseconds AThe OS quickly changes the CPU from one running program to another so that all the programs keep making progress
2switch_to(next_program) BThe short period of CPU time given to one program before the OS moves on to the next program
3Several programs are open at once, and the OS gives each one a turn on the CPU in a repeating loop CEach program is run to the end before the next one starts, so the CPU time is not shared in short slices and the programs do not appear to run together.
4The OS keeps each program's work separate by storing its own data so one program does not overwrite another Dmemory[program] = own_data
5run(music_player) run(web_browser) Efor program in open_programs: run(program, time_slice)
6one_program_at_a_time = True FThis setting stops the OS from switching between programs, so only one program can use the CPU and multitasking cannot happen.

Definitions

multitasking

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
OS function: ____________
2.
giveCPU(program, _________)
3.
_________(currentProgram)
4.
IF programs _ 1 THEN multitasking ← TRUE
5.
_____ timeLeft > 0 DO run(program)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A apps ← [Game, Music, Chat]
B slice ← 10
C FOR EACH app IN slice
D CPU runs app for slice ms
E NEXT app
Question 2
A IF computer is on
B run Browser for 1 slice
C run Music for 1 slice
D ENDWHILE
Question 3
A CPU runs Music for one slice
B Music must finish completely
C OS saves Music's progress
D OS loads Chat's progress
E CPU runs Chat for one slice
Question 4
A Music ← memory block A
B Chat ← memory block A
C Blocks do not overlap
D Each program stays separate
Question 5
A slice ← 10
B WHILE apps are open
C CPU runs app for slice ms
D Stay on the same app
E ENDWHILE

Answer Key

OS function: managing multitasking
Section A: Quick Questions
Q1
A — The OS shares CPU time between programs in very short slices
Q2
A — Managing multitasking
Q3
A — It switches the CPU to another program
Q4
B — Very short, so switching looks instant to the user
Q5
B — So one program's data does not overwrite or mix with another's
Section B: Match the Pairs
Q1
time_slice = 10 # milliseconds → The short period of CPU time given to one program before the OS moves on to the next program
Q2
switch_to(next_program) → The OS quickly changes the CPU from one running program to another so that all the programs keep making progress
Q3
Several programs are open at once, and the OS gives each one a turn on the CPU in a repeating loop → for program in open_programs: run(program, time_slice)
Q4
The OS keeps each program's work separate by storing its own data so one program does not overwrite another → memory[program] = own_data
Q5
run(music_player) run(web_browser) → Each program is run to the end before the next one starts, so the CPU time is not shared in short slices and the programs do not appear to run together.
Q6
one_program_at_a_time = True → This setting stops the OS from switching between programs, so only one program can use the CPU and multitasking cannot happen.
Section C: Definitions
Q1
multitasking — The OS runs several programs at once by sharing CPU time in very short slices and switching quickly between them, so they appear to run together.
Section D: Fill in the Blanks
Q1
OS function: multitasking
Q2
giveCPU(program, timeSlice)
Q3
saveState(currentProgram)
Q4
IF programs > 1 THEN multitasking ← TRUE
Q5
WHILE timeLeft > 0 DO run(program)
Section E: Spot the Error
Q1
C — The loop must go through the list of open programs, so it should be FOR EACH app IN apps. slice is just a number, so the loop has nothing to go through.
Q2
A — Multitasking keeps sharing CPU time for as long as the computer is on, so it needs a repeating loop. It should be WHILE computer is on. An IF would only give each program one turn.
Q3
B — The OS switches programs when the time slice ends, not when the program finishes. The line should say the time slice ends, for example 'Time slice ends'.
Q4
B — Each program's work must be kept separate. Chat has to use a different block (B), otherwise it would overwrite Music's data in block A.
Q5
D — After each short slice the OS must switch quickly to the next program. Staying on the same app would stop the others from running, so the line should be 'Switch to next app'.