Operating Systems manage the essential functions of a computer, allowing users and applications to interact with hardware without needing to understand its complexity.
Hiding hardware complexity
Abstracting the physical layer
At its core, the operating system (OS) serves as a bridge between hardware and software, ensuring users and applications can interact with the system without needing to understand the low-level details of the hardware itself. This process is called abstraction. The OS provides a simplified interface for accessing hardware functions, so neither users nor developers need to worry about the specific architecture or communication protocols of the underlying components.
Instead of interacting directly with the CPU, memory chips, hard drive, or peripheral devices, software applications issue high-level requests (e.g. open a file, display an image). The OS takes these requests and translates them into the necessary machine-level instructions to control the hardware.
Without this abstraction:
Applications would have to be rewritten for each different type of hardware.
Users would need technical knowledge of their system to operate basic functions.
The OS effectively hides the complexities of machine architecture by offering a consistent set of tools and interfaces.
Example: file saving and reading
Suppose a user clicks “Save” in a word processor. This simple action triggers several processes:
Practice Questions
FAQ
When the operating system runs out of physical memory (RAM), it activates a process known as paging to extend usable memory using a section of the hard disk called virtual memory or swap space. The OS identifies less frequently used pages in RAM and temporarily moves them to the disk. This frees up space in RAM for processes that are currently active and require immediate access. The OS uses a page table to track where each page is stored, whether in physical memory or virtual memory. When a program needs data that has been swapped out, a page fault occurs, and the OS retrieves the data from disk and replaces it in RAM. Although this process allows more programs to run simultaneously, accessing data from disk is much slower than RAM, so system performance may degrade. Still, this mechanism prevents crashes and enables the system to operate under memory pressure.
The OS uses scheduling algorithms to manage how the CPU is shared among multiple processes, especially when the system is heavily loaded. These algorithms determine which process runs next based on criteria like execution time, priority level, and resource requirements. For example, in priority scheduling, processes with higher priority values are executed first. The OS may assign priorities dynamically based on factors such as user interaction or system importance. In contrast, round robin ensures fairness by giving each process a fixed time slice in turn. More complex methods, such as multilevel queue scheduling, categorise processes into different queues (e.g. interactive tasks vs background services), each with its own scheduling rules. The OS constantly evaluates the state of all processes and may pre-empt a lower-priority task if a more urgent one becomes ready. This ensures responsive performance for critical tasks while still progressing background operations efficiently.
To prevent two processes from accessing the same memory space simultaneously, the operating system implements memory protection mechanisms. Each process is assigned a unique portion of memory, and the OS uses a memory management unit (MMU) to enforce boundaries. The MMU translates logical addresses used by processes into physical addresses and checks each memory access against a set of rules. If a process tries to access memory outside its allocated region, a segmentation fault or access violation occurs, and the OS intervenes, usually terminating the process to maintain system integrity. The OS also employs techniques like paging and segmentation, which include permission bits that define whether a page or segment can be read, written, or executed. In systems supporting virtual memory, each process believes it has its own memory space, which is isolated from others, even though the physical memory is shared. This approach ensures data security, prevents corruption, and avoids unpredictable behaviour.
A deadlock occurs when two or more processes are waiting for each other’s resources indefinitely, preventing further progress. To manage deadlocks, the operating system may employ several strategies: prevention, avoidance, detection, and recovery. In deadlock prevention, the OS ensures that one of the four conditions for deadlock—mutual exclusion, hold and wait, no pre-emption, and circular wait—cannot occur. For example, it may require processes to request all resources at once. Deadlock avoidance uses algorithms like the Banker’s Algorithm to assess whether granting a resource could lead to an unsafe state and denies access if it might. In deadlock detection, the OS allows deadlocks to occur but regularly checks for them using resource allocation graphs. If detected, the OS selects a victim process to terminate or roll back, releasing resources to break the deadlock. Each strategy has trade-offs between performance, complexity, and system efficiency, and the choice depends on the system’s goals and workload.
To maintain file system integrity during unexpected shutdowns or crashes, the operating system uses a combination of journaling, caching, and synchronisation mechanisms. In a journaling file system, every file operation (such as creation, deletion, or modification) is first recorded in a journal or log. Only after the change is safely logged does the OS apply the operation to the actual file system. If a crash occurs before the change is committed, the journal can be replayed or rolled back to restore a consistent state. Additionally, the OS uses write caching to temporarily store file changes in memory, improving performance. However, these caches are flushed to disk regularly using synchronisation routines (like sync) to reduce the risk of data loss. The OS also marks the file system as ‘clean’ or ‘dirty’ based on the completion of operations. On reboot, the OS performs file system checks (e.g. using fsck) to repair any inconsistencies and restore reliability.
