Resource Management Techniques and OS
Operating systems (OS) are responsible for managing system resources to ensure efficient and reliable operation.
It abstracts the complexity of hardware, allowing users and applications to interact with the system without needing to understand the underlying details.
The OS is like a translator, converting user commands into machine instructions and vice versa.
- In Windows, drive letters (e.g., C:, D:) represent storage devices.
- This abstraction allows users to interact with storage as if it were a simple directory structure, hiding the complexity of file systems and physical storage locations.
- Additionally, OS is responsible for localisation, which involves adapting software for different regions, including language, currency, and date formats.
- This can cause compatibility issues if systems are not properly configured.
- For example, some countries use different naming conventions, leading to conflicts when sharing files.
Resource management that OS does involves a range of techniques designed to optimise the use of hardware and software resources.
Scheduling
Scheduling
The process of determining which tasks or processes should be executed by the CPU at any given time.
Scheduling is crucial for maximising CPU utilisation and ensuring that all processes receive fair access to resources.
There exist different scheduling strategies, such as:
- First-Come, First-Served (FCFS):
- Processes are executed in the order they arrive.
- Use Case: Simple environments where fairness is prioritised over efficiency.
- Shortest Job First (SJF):
- Executes the process with the shortest execution time first.
- Use Case: Ideal for batch processing systems to minimise average waiting time.
- Round Robin (RR):
- Each process is given a fixed time slice (quantum) before moving to the next.
- Use Case: Multitasking syscctems where responsiveness is critical.
- Priority Scheduling:
- Processes are executed based on priority levels.
- Use Case: Real-time systems where certain tasks must be completed urgently.
The scheduler is a component of the OS that implements these algorithms, balancing factors like CPU utilisation, throughput, and response time.
Preemptive Scheduling is when high-priority tasks can interrupt lower-priority ones, ensuring critical tasks are completed first.
Policies
Policies
The rules and guidelines for managing resources and user access within a system.
Policies define
- User Accounts and Permissions:
- Each user has a unique account with specific access rights.
- Use Case: Ensures security and prevents unauthorised access to sensitive data.
- Resource Allocation:
- Policies determine how resources like CPU time and memory are distributed among processes.
- Use Case: Prevents resource starvation and ensures fair distribution.
- Policies are distinct from mechanisms.
- While policies define what should be done, mechanisms define how it is implemented.
Multitasking
Multitasking allows multiple tasks or processes to run concurrently, giving the illusion of parallel execution via:
- Time Slicing:
- The CPU switches between tasks at regular intervals, known as time slices.
- Use Case: Ensures that all tasks receive CPU time, maintaining system responsiveness.
- Context Switching:
- The OS saves the state of a running process and loads the state of the next process.
- Use Case: Enables efficient multitasking by allowing the CPU to switch between tasks seamlessly.
Multitasking relies on interrupts to pause and resume tasks, ensuring that no single process monopolises the CPU.
Virtual Memory
Virtual memory
A technique that allows a computer to use secondary storage (e.g., a hard drive) as an extension of primary memory (RAM).
An example of a virtual memory technique is paging:
- Memory is divided into fixed-size blocks called pages.
- When RAM is full, inactive pages are moved to disk.
- Use Case: Enables systems to run applications larger than the available RAM.
Paging:
- Increases memory capacity: Allows more applications to run simultaneously
- Isolates processes: Each process operates in its own virtual address space, enhancing security and stability.
Excessive paging can lead to thrashing, where the system spends more time swapping pages than executing tasks.
Interrupts
Interrupts
Signals that inform the CPU of an event that requires immediate attention
- Interrupts pause the current task, execute a specific routine (interrupt handler), and then resume the task.
- They are essential for real-time systems where timely response to events is critical.
We can distinguish two types of interrupts:
- Hardware Interrupts: Triggered by devices (e.g., keyboard input, disk I/O).
- Software Interrupts: Generated by programs requesting OS services.
Interrupts enable multitasking by allowing the OS to switch between tasks based on priority and system events.
Polling
Polling
Polling is a technique where the CPU repeatedly checks the status of a device at regular intervals to see if it needs attention.
Polling is usually used in simple systems where interrupts are not feasible or necessary.
There are some drawbacks when using polling:
- Inefficient: Consumes CPU time even when no action is required.
- Real-Time Applications: Unlike interrupts, polling does not rely on signals from devices, making it less efficient for real-time applications.
Polling is like checking your phone repeatedly for messages, while interrupts are like receiving a notification when a message arrives.
Why These Techniques Matter
Such techniques improve:
- Efficiency: Ensuring that system resources are used optimally, reducing waste and improving performance.
- Scalability: Techniques like virtual memory and multitasking enable systems to handle larger workloads and more complex applications.
- Reliability: Interrupts and scheduling policies ensure that critical tasks are prioritised, maintaining system stability and responsiveness.
Input and Output Devices
Additionally, the OS manages input devices (e.g., keyboards, mice) through device drivers.
These drivers act as intermediaries, translating hardware signals into actions the OS can understand.
Settings can be adjusted (e.g., mouse sensitivity) without modifying the hardware.
When you move a mouse, the OS translates the movement into cursor actions on the screen, hiding the complex communication between the mouse and the computer.
- How does virtual memory enable a system to run applications larger than its available RAM?
- Why might an OS choose polling over interrupts in certain situations?
- How does the OS use virtualisation (virtual memory, virtual machine) to simplify hardware interactions?
- Why is abstraction important for developers and users?
- Can you think of other examples where the OS hides complexity?
- How does the OS manage memory for multiple programs running simultaneously?
- What role do device drivers play in peripheral management?
How does the abstraction of hardware by operating systems influence our perception of technology?