Scheduling
Scheduling
What is Scheduling?
Deciding which tasks to process, for how long, and in what order is achieved
through scheduling algorithms
A CPU is responsible for processing tasks as fast as possible
Different algorithms are used to prioritise and process tasks that need CPU time
The algorithms have different uses, benefits and drawbacks.
Scheduling categories
Preemptive Scheduling
Non-Preemptive Scheduling
Once the CPU is allocated to a process, the process holds it until it completes
its burst time or switches to a 'waiting' state
A process cannot be interrupted unless it completes or its burst time is reached
If a process with a long burst time is running, shorter processes will be neglected
Example algorithms include First Come First Serve and Shortest Job First
Scheduling Algorithms
First-Come-First-Served (FCFS)
Exam Tip
The main benefit of memory management is to make computer systems run smoothly.
Most users don’t realise that as they effortlessly move between applications, it’s made
possible because the OS is rapidly reallocating memory depending on the task that the
user is completing.
Make sure you can name one benefit and one drawback for each memory management
method in this revision note.
Paging
What is Paging?
Segmentation
What is Segmentation?
Virtual Memory
Virtual Memory
If a computer is running low on primary memory, it can make secondary storage act as
an 'extension' of the main memory
The operating system can offload data from the primary memory into virtual memory
Virtual memory creates an illusion of a larger memory and enables applications to
continue to multitask
However, accessing data in virtual memory is considerably slower compared to RAM
Solid-state drives are faster than traditional hard-disk drives, but neither are as fast as
RAM
Over-reliance on virtual memory can lead to performance issues
Memory
Management Description Example Benefits Drawbacks
Technique
Worked example
Describe how the operating system would use virtual memory to load program C when there's
not enough space in physical memory.
[3]
The operating system can use virtual memory to act as an extension of the computer's primary
memory. This means less-critical data can be offloaded from the primary memory into virtual
storage, useful when a higher-priority set of processes require immediate attention. If the OS
offloaded data from the RAM into virtual memory, this would free up space for program C to be
loaded into RAM.
Program C can be loaded into the RAM if the operating system moves files and data into virtual
memory. Virtual memory acts as an extension of the RAM.
Worked example
Describe two ways that an operating system could manage physical memory.
[4]
How to answer this question
Imogen's operating system could manage physical memory in two ways. Paging, which is a
method of dividing memory into fixed-size chunks known as pages. Application data can be
allocated and deallocated to pages making it a flexible system depending on the activity of the
user.
The system could also use virtual memory, a method of extending the available physical memory
by using a portion of the hard drive. This allows more programs to run simultaneously and
enhances the overall system performance.
Imogen's computer uses paging to manage memory. This means it breaks down the memory into
fixed-size pieces and swaps them in and out as needed.
The computer also uses something called virtual memory. It uses part of the hard drive to act like
extra memory, so more programs can run at the same time, and everything works faster.
Worked example
Explain why a First Come First Served scheduling algorithm would not be suitable in
this situation.
[2]
Using FCFS could delay these critical tasks if many other processes are in the queue
ahead of the anti-virus software. Other less crucial tasks could get CPU time before the
anti-virus process, leading to potential security risks.
System Interrupts
What are interrupts?
An interrupt is a signal to the processor that stops its current task and performs
a different task temporarily
Interrupts can be hardware events or time-sensitive tasks
When an interrupt occurs, the processor suspends the current
program execution and transfers control to an interrupt service routine
Real-time Event Handling: hardware errors and signals from input devices e.g.
hard disk failure
Device Communication: alerts from external devices e.g. printer jams and
network errors
Multitasking: suspending processing in one application so that the user can
switch to another
Types of Interrupts
What is an ISR?
An ISR is a special function that handles a particular interrupt type
Each type of interrupt has a corresponding routine, e.g. printer jam, hard disk
failure, file download error, network connection error all have routines to be
followed when they happen
ISRs should be concise, efficient, and carefully designed to minimise the time
taken to execute, as they often need to handle time-sensitive events
Nesting of interrupts
Worked example
Adding a DVD drive to a computer often requires the installation of a piece of software
called a device driver.
Pick one example of a hardware device and describe what happens between it
and the operating system
Explain that this is made possible through device driver software
The purpose of a device driver is to enable the operating system to interact with and
control a hardware device. For example, a printer would have an associated device
driver so the OS could send or receive data from a printer system.
Virtual Machines
What are virtual machines?
Virtual machines (VMs) are entire operating systems running inside another
operating system
A user running Windows 11 could run a virtual machine of MacOS
This would allow them to navigate the GUI of MacOS and install software on it
Running a virtual machine helps access software that is only designed to run on
specific operating systems
VM management software includes a Hypervisor that monitors all activity
happening inside the VM
In software testing
VMs are a way to create isolated test environments, that leave the host
operating system unaffected
Isolated environments allow a developer to:
o Monitor the way their software affects system performance
o Test on a clean-slate system, while no other applications are running
VM management software can create virtual machines that act like they
have older hardware
This allows developers to build software that can be run on older hardware so
that more users can use the software
A developer can test against various operating systems, such as MacOS,
Linux and Windows, for greater compatibility
This is achieved through compiling into intermediate code and running against
different operating systems
Consequences
Worked example
Explain why the programmers of anti-virus software may make use of virtual machines
when developing the updates.
[3]
Virtual machines (VMs) are essential in developing anti-virus software updates for
several reasons. VMs create an isolated environment that is separate from the host
operating system. This enables developers to safely work with virus test code that could
risk the integrity of their own operating system. VMs can also be configured to emulate
various types of hardware. This allows developers to understand how their anti-virus
software will perform on different devices and under different conditions, ensuring a
wider range of compatibility.
Virtual machines create an isolated test environment from the host operating system.
This means working with harmful test code carries less risk. Virtual machine
management software can monitor the VM through the Hypervisor. This will show how
the software affects VM system performance, allowing the programmer to make
changes where needed.
Stages of Compilation
What is Compilation?
Lexical Analysis
o Keywords
var, const, function, for, while, if
o Identifiers
Variable names, function names
o Operators
'+', '++', '-', '*'
o Separators
',' ';', '{', '}', '(', ')'
During this stage, unnecessary elements like comments and whitespace are
ignored
For example, if the following code is being compiled:
var x = function(x,y) {
if(x>2) {
return x*y;
}
return x+y;
}
1 var Keyword
2 x Identifier
3 = Operator
4 function Keyword
5 ( Separator
6 x Identifier
7 , Separators
8 y Identifier
9 ) Separator
10 { Separator
11 return Keyword
12 x Identifier
13 * Operator
14 y Identifier
15 ; Separator
16 } Separator
Syntax Analysis
Now that tokens have been identified, syntax analysis makes sure they
all adhere to the syntax rules of the programming language
A symbol, e.g. '$' could be a valid token but not a valid character according to
particular programming languages
The dollar symbol would be flagged as breaking the syntax rules
Other syntax errors programmers commonly make include mismatched
parentheses or missing semicolons
If the code passes the syntax analysis, the compiler can create an Abstract
Syntax Tree (AST)
An AST is a graph-based representation of the code being compiled
An AST is an efficient way to represent the code for the next step
Example abstract syntax tree
For the same code as above, the following abstract syntax tree can be created
Code Generation
This step takes the AST and traverses it to generate object code that can be
executed by the computer
Optimisation
This step modifies the code to make it more efficient without changing its
functionality
This is important to attempt because it reduces the memory required to run the
code, which leads to faster execution
A common optimisation action is removing duplicate code
If an 'add' function is written twice in the source code, a sophisticated compiler
will notice this and include it only once in the object code
Worked example
Imogen is writing application software for her company and is ready to compile it.
[2]
'Lexical analysis' breaks the code into tokens, ignoring whitespace and comments.
Tokens are identified by their type:
keyword: 'return'
operator: '*', '-'
identifier: celsius, fahrenheit
delimiter: ';', '(', ')' etc
When all tokens have been identified, a token table is produced for the next step in the
compilation.
The compiler will look at all the lexical tokens in the code e.g. 'fahrenheit' is an identifier,
'return' is a keyword. All the tokens are placed into a tokens table for the next step