Why is an operating system needed?
An OS is needed to manage hardware, provide a platform for software, handle resources, ensure security, manage files, manage memory, schedule tasks, handle interrupts, and provide a user interface.
It acts as the intermediary between user programs and hardware.
Core functions of an operating system
What are drawbacks or limitations of operating systems?
Complex OSs require more hardware resources (RAM, CPU).
Bugs in the OS can impact entire system stability.
Security vulnerabilities can be exploited if not updated.
Hard-to-learn interfaces (e.g., CLI) can reduce usability.
Strict OS rules limit direct hardware access for programmers.
What is paging?
Paging divides memory into fixed-size blocks (pages).
Processes are stored in these equal-sized pages, enabling them to be loaded into any free memory frame.
Supports virtual memory because pages can be swapped in/out of secondary storage.
Benefits and drawbacks of paging
Benefits: Simple, allows non-contiguous memory, (non adjacent memory locations) supports virtual memory.
Drawbacks: Pages may not align with logical structures → inefficient. Page tables create overhead. (the resources, are consumed by the system to manage itself, rather than for performing the primary task)
What is segmentation?
Memory is divided into logical segments (e.g., code, stack, data).
Segments vary in size based on program structure.
More meaningful than paging because it reflects how programs are written.
What are the benefits of segmentation?
Segments are logical divisions → easier program organisation (e.g., code, stack, heap).
Segments can be sized exactly → reduces internal fragmentation.
Supports protection, as individual segments can have different access rights.
Allows for sharing of segments between processes (e.g., shared libraries).
What are the drawbacks of segmentation?
Causes external fragmentation because segments vary in size.
Harder for the OS to manage compared to fixed-size pages.
More complex memory allocation algorithms.
Moving segments around to defragment memory increases overhead.
What is internal fragmentation?
Internal fragmentation occurs when fixed-size memory blocks are allocated to a process, but the process doesn’t fully use the entire block, leaving unused space inside the allocated block.
This waste occurs most commonly when paging is used.
Why does internal fragmentation happen?
Because paging uses fixed-size pages/frames (e.g., 4 KB).
If a process needs memory that is not a perfect multiple of the page size, the last page is not fully used → wasted space.
Example of internal fragmentation
Process needs 10 KB, page size 4 KB → allocation needs 3 pages (12 KB).
Only 10 KB is used → 2 KB is wasted inside the last page.
Benefits of paging (despite internal fragmentation)
Very simple allocation (fixed-size blocks).
Eliminates external fragmentation.
Pages can be swapped in/out easily → supports virtual memory efficiently.
Drawbacks of internal fragmentation
Memory is wasted inside allocated pages.
More RAM is consumed → can force the OS to use virtual memory earlier → slower performance.
Particularly bad for many small processes.
What is external fragmentation?
External fragmentation occurs when free memory is split into many small non-contiguous blocks, so although the total free space is large, no single large block is available for a process that needs one.
Occurs most with segmentation (variable-sized blocks).
Why does external fragmentation happen?
Because segmentation allocates variable-sized memory segments.
As processes are loaded/unloaded, free gaps appear between segments → memory becomes “fragmented”.
Example of external fragmentation
Free memory: 20 MB total → blocks are: 8 MB + 6 MB + 6 MB.
A process needs 10 MB, but no single free block is ≥ 10 MB → allocation fails.
Benefits of segmentation (despite external fragmentation)
Memory fits closer to program structure (code, stack, heap).
Allows variable-sized allocation → reduces internal waste.
Supports protection + sharing at the segment level.
Drawbacks of external fragmentation
Free memory becomes unusable due to scattered gaps.
Requires compaction (expensive) to rearrange segments.
Slows allocation because OS must search for a block big enough.
Can eventually make RAM inefficiently utilised.
Key difference between internal vs external fragmentation
Internal: Waste inside allocated blocks, caused by fixed-size pages.
External: Waste between allocated blocks, caused by variable-size segments.
Paging vs Segmentation
Paging: Fixed size, physical division, simple but not logical.
Segmentation: Variable size, logical division, matches program structure.
OSs may use both.
What is an Interrupt Service Routine (ISR)?
A predefined routine the CPU jumps to when an interrupt occurs.
Handles the event (e.g., read input, complete I/O, manage error).
Stored in interrupt vector table.
What is an interrupt and how does an Interrupt Service Routine (ISR) work?
An interrupt is a signal that temporarily halts the CPU so an urgent event can be handled.
When triggered, the CPU finishes its current instruction, saves its state to the stack, and jumps to the appropriate ISR using the interrupt vector table.
The ISR handles the event (e.g., I/O, errors, timer), then the CPU restores the saved state and resumes the interrupted program.
This allows multitasking, efficient I/O, and rapid response to external/internal events.