1.2.1 Systems Software
Operating Systems
An operating system manages hardware and software resources, as well as providing an interface between user and hardware.
Resource Management
The first of seven categories, the OS is responsible for resource management. They allocate resources (RAM, CPU, and Storage) to specific tasks and try to maximise performance and power-efficiency. For example, the scheduler in an OS is responsible for prioritising what runs next on a CPU, so if you, for example, open a game, it will prioritise allocating resources to that, rather than OneDrive syncing in the background (more on these later).
File Management
The OS is also responsible for file management - that is, working with the file system that the drive is formatted with in order to store, retrieve, and manipulate data. OSes will provide some sort of user interface, usually a GUI, to allow the user to interface with the file system and gives files properties e.g. file names, directory the file is stored in, dates modified, EXIF data, etc.
Interrupt Handling
Interrupts are events that require the immediate attention of the CPU, such as mouse movements. These must be processed quickly in order for the system to feel responsive and respond to time-sensitive actions e.g. cancelling file deletion (more on these later).
Security
Operating systems usually provide some sort of security suite such as a firewall (e.g. nftables), virus scanning (e.g. Windows Defender), and file encryption (e.g. BitLocker). Different accounts on the system can be given various permissions, such as file permissions, being allowed to install software globally, and editing the firewall settings, etc.
Providing a Platform for Software
Software from third-parties will need to access system resources, and this is the responsibility of the operating system. This is done via system calls (syscalls), where a program will ask the opearting system to give it access to resources to allow it to carry out a task e.g. write data to a file, or render triangles on a GPU.
Providing UIs
Users need User Interfaces (obviously) in order to interact with a computer. An operating system at the very least will provide a CLI (command-line interface), but usually a GUI (graphical user interface) too. On mobile OSes such as iOS the CLI is usually hidden and only used for debugging, as mobile OSes need to optimise for ease-of-use through touch-friendly GUIs.
Graphical User Interfaces
Graphical User Interfaces (GUIs) are the most common type of user interface, and they allow users to interact with a computer using visual elements such as windows, icons, and menus. GUIs are designed to be intuitive and user-friendly, making it easier for users to navigate and perform tasks on a computer. They often include features such as drag-and-drop functionality, context menus, and visual feedback to enhance the user experience.
Command-Line Interfaces
Command-Line Interfaces (CLIs) are text-based interfaces that allow users to interact with a computer by typing commands into a terminal or console. CLIs provide a powerful and flexible way to control a computer, allowing users to execute commands, run scripts, and automate tasks. They are often preferred by advanced users and system administrators for their efficiency and ability to perform complex operations quickly. CLIs can be used to manage files, configure system settings, and execute programs, among other tasks. They are also commonly used in server environments where a GUI may not be available or necessary, as they consume fewer system resources and can be accessed remotely via SSH (Secure Shell) or other remote access protocols.
Menu-Driven Interfaces
Menu-driven interfaces are a type of user interface that presents users with a list of options or commands in the form of menus. Users can navigate through the menus using keyboard or mouse inputs to select the desired option. Menu-driven interfaces are often used in applications and systems where users need to perform specific tasks or access certain features without having to remember complex commands. They provide a structured and organized way for users to interact with a computer, making it easier for them to find and execute the desired actions. Menu-driven interfaces are commonly found in software applications, ATMs, and other devices where a simple and straightforward user experience is required.
Natural Language Interfaces
Natural Language Interfaces (NLIs) allow users to interact with a computer using natural language, either through text or speech. NLIs use natural language processing (NLP) techniques to understand and interpret user input, enabling users to communicate with the computer in a more intuitive and human-like manner. NLIs are often used in virtual assistants, chatbots, and voice-controlled systems, allowing users to ask questions, give commands, and receive responses in a conversational format. They aim to make the interaction with computers more accessible and user-friendly, especially for users who may not be familiar with traditional interfaces or technical terminology. NLIs can also be used in applications that require complex queries or commands, allowing users to express their intentions in a more natural and flexible way. They also suck.
Utility Software
Utility software allows for the maintenance of the hardware and software systems running a computer. OSes will usually include at least a very basic set of utility software such as disk formatting, file compression, and package management.
Interrupts
A device or a piece of software can generate an interrupt and send this to the processor to trigger an ISR (interrupt service routine). They are used for handling real-time events such as mouse movements, device communication such as incoming network connections, and multitasking. They are concise and have a specific purpose.
| Type | What it does |
|---|---|
| Hardware Interrupts | Asynchronous interrupts generated by external devices, and will cause an ISR to run that will, for example, process a keyboard input in a game. |
| Software Interrupts | Synchronous interrupts triggered by software or the OS itself, often generated when errors occur e.g. a network error, but also when I/O operations are needed such as when opening a file. |
| Trap Interrupts | A type of software interrupt triggered by a user program’s instruction, such as a system call or an exception like division by zero, which forces the CPU to switch to kernel (low-level OS) mode and execute a handler before returning to the user process. |
Note
A kernel is often referred to as the ‘core’ of an OS, which handles the interface between hardware and software and contains software such as basic device drivers and the code to power on a system once the BIOS/UEFI has handed it control.
If the interrupt is of a lower/equal priority to the current process then the current process continues. Otherwise:
- The contents of the registers are copied to a stack (special area of memory).
- The interrupt flag is set.
- The program counter is changed to point to the ISR. If a higher-priority interrupt comes in during handling, the lower-priority interrupt is added to the stack and the higher-priority one is dealt with first. Interrupts can also be nested, where an ISR could trigger another interrupt, and the CPU deals with these.
- After the interrupt completes, the previous register values are restored back from the stack and the interrupt flag is reset.
Important
Interrupts are not always run - masked interrupts are hardware interrupts that can be ignored or disabled by the system using interrupt-masking techniques, selectively ignoring non-critical interrupts. They help in managing system resources and are used routinely during normal system operation.
Memory Management
Memory management is the function of the operating system that deals with the allocation and deallocation of system memory. It ensures that processes cannot access memory used by each other for security, and enables multitasking as the correct amount of memory can be reserved for each program.
Paging
A technique to make memory management more efficient is paging. It’s where memory is chunked into equal size blocks. When memory is needed, for example for a program, data and instructions for that program get moved from secondary storage into pages. Pages are dynamically allocated, and this allows for pages to be moved into a page file in virtual memory when RAM is full (more on this later). However, this can lead to fragmentation, similar to an HDD. If a program needs 550kB of RAM and this is split into 128kB pages, this means that the fifth page will only be about 30% utilised. Over time, more of this wasted space will exist across memory, this is called internal fragmentation and will need to be cleaned up by the OS.
Segmentation
Segmentation divides a program into different logical segments based on its structure. Each segment represents a distinct part of the program, such as functions or data structures. This method allows only the necessary parts of a program to be loaded into memory when needed, optimising memory usage and potentially improving performance. Unlike paging, which divides memory into fixed-size blocks, segmentation creates segments of varying sizes based on the program’s logical structure. This means that they are not subject to internal fragmentation, but are subject to external fragmentation. As blocks are removed, there is no way of guaranteeing that new blocks take up the same amount of space and therefore the space needs to be defragmented.
Virtual Memory
If a computer is low on RAM (primary memory), it can move data from RAM into secondary storage, such as an HDD or SSD. This prevents the computer from running out of memory, but secondary storage is much slower than primary and so it can significantly slow down the computer. To try to combat this, the OS will move data and instructions not in use by the user - such as background apps or idle tabs - into virtual memory. This will be stored in a “page file”, as “swap”, and/or as “zram” - these are all terms for the same thing. Data needs to be moved back to RAM from virtual memory when accessed.
Scheduling
Scheduling is where the OS decides what task to process, when to process it / which order to process in, and for how long. There are multiple types of scheduling algorithm, which fall into two categories:
- Pre-emptive scheduling: allocates the CPU for a very brief duration of time - a time quantum (the shortest possible amount of time). It allows interruption of current processes which can result in lower priority processes never being executed if there are too many high-priority processes.
- Non-pre-emptive scheduling (creative name I know): the process running is allowed to complete - its burst time - or until it hits a waiting state (for example when waiting for files on disk). A process cannot be interrupted until these conditions are met, and this ensures lower-priority processes run but if a process with a long burst time is running, other processes may be neglected.
Algorithms
There are two pre-emptive algorithms, and two non-pre-emptive.
Round Robin
This is a pre-emptive algorithm that equally distributes processor time across all architectures. Processes that are ready to be worked on get queued (the length of this is the processor queue length). If a process doesn’t complete by the end of its time quantum, it gets moved to the back of the queue and waits to be moved to the front again. As new tasks come in, they have to be added to the queue, so this can result in a bit of a queue before the queue when the scheduler is working.
Multi-Level Feedback Queue
Pre-emptive: shorter and more critical tasks are processed first. Every task joins the first (highest priority queue), dropping down to lower priority queues as time quantum is exceeded. This results in long-duration background tasks taking longer, but the system feeling more responsive.
Shortest Job First
Non-pre-emptive. Processes are added to the queue based on their burst time in the next cycle (processes that will take longer, but free up the CPU quickly due to waiting for disk etc, wil be executed quickly).
Shortest Remaining Time First
SRTF is similar to SJF, but it is pre-emptive, which means it can interrupt a currently running process if a new process with a shorter burst time arrives. This guarantees the minimum average waiting time.
First-Come-First-Served
Does what it says on the tin. Non-pre-emptive; processes being worked on block everything else until they are complete.
Comparison
| Algorithm | Advantages | Disadvantages |
|---|---|---|
| Round Robin | Fair; responsive | Higher context-switching overhead |
| MLFQ | Very responsive; prioritises short/important tasks | Complex; long tasks may starve |
| SJF | Low average waiting time | Long tasks may starve; burst time must be estimated |
| SRTF | Very low average waiting time | More context switching; starvation possible |
| FCFS | Simple; easy to implement | Poor responsiveness; convoy effect |
Types of Operating Systems
There are five main types of operating system, which are categorised based on their intended use and the way they manage resources. These are:
- Distributed OS: manages a group of independent computers and makes them appear to be a single computer. It allows for resource sharing, load balancing, and fault tolerance across multiple machines.
- Embedded OS: designed to operate on embedded systems (specific devices), which are dedicated to specific tasks. They are optimised for efficiency and reliability, often with real-time capabilities, consuming less power and resources than other OS types.
- Multitasking OS: allows multiple processes to run concurrently on a single CPU, managing the allocation of CPU time and resources to ensure that each process gets a fair share of the system’s capabilities. This is done via time slicing, where the CPU switches between programs and applications in memory very quickly.
- Multi-user OS: allows multiple users to access a computer system concurrently, usually something powerful like a supercomputer. Because of this, a scheduling algorithm must be used, similarly to multitasking OSes, to ensure that all users get a fair share of the system’s resources. A bad scheduling algorithm could result in process starvation.
- Real-time OS: designed to process data and events within a strict time constraint, often used in systems where timing is critical, such as industrial control systems, robotics, and embedded systems. They prioritise tasks based on their urgency and ensure that critical tasks are completed within their deadlines.
Basic Input/Output System (BIOS), Device Drivers, and Virtual Machines
BIOS
The BIOS is a firmware that initialises and tests hardware components during the booting process of a computer. It is the first program that runs when a computer is powered on, and it provides a low-level interface between the operating system and the hardware. The BIOS is responsible for performing the Power-On Self Test (POST), which checks the functionality of essential hardware components such as the CPU, RAM, and storage devices. It also loads the bootloader, which in turn loads the operating system into memory.
Device Drivers
Device drivers are software components that allow the operating system to communicate with hardware devices. They act as intermediaries between the operating system and the hardware, translating high-level commands from the OS into low-level instructions that the hardware can understand. Device drivers are essential for the proper functioning of hardware devices, as they enable the operating system to control and interact with peripherals such as printers, graphics cards, network adapters, and storage devices. Without the appropriate device drivers, the operating system would not be able to utilise the hardware effectively, leading to reduced functionality or complete incompatibility.
Device drivers are specific to the computer’s architecture and specific to the operating system. For some operating systems, such as Linux, many “generic” device drivers are included in the kernel, which allows for a wide range of hardware to be supported out-of-the-box. However, for other operating systems, such as Windows, device drivers may need to be installed separately, either from the manufacturer’s website or from installation media provided with the hardware.
Virtual Machines
Virtual machines are theoretical computers that are a software implementation of a computer system. They provide environments with translators for intermediate code (code that is half-way between source code and machine code, such as Java bytecode or Common Intermediate Language) to run.
Virtual machines allow for the execution of multiple operating systems on a single physical machine, enabling users to run different OSes simultaneously without the need for separate hardware. They provide isolation between the host operating system and the guest operating systems, allowing for testing, development, and experimentation without affecting the stability of the host system. This saves time and money, but VMs can be far slower than running the OS natively, as they require additional resources to emulate the hardware and manage the virtual environment.
Additionally, as virtual machines allow for separate operating systems to run on the same physical hardware, they can be used for sandboxing. This is where a potentially unsafe program can be run in a virtual machine, and if it is malicious, it will not affect the host operating system or other virtual machines running on the same hardware. They can also be used for running incompatible software, such as running Windows-only software on a Linux host OS, or running old software that is no longer compatible with modern operating systems.
Note
Virtual machines are not impenetrable: they are software, and all software has bugs. There have been many vulnerabilities in virtual machine software that have allowed malicious software to escape the virtual machine and infect the host OS.