Understanding Multitasking and Resource Allocation
Multitasking
Multitasking is the ability of an operating system (OS) to manage and execute multiple processes simultaneously.
Resource allocation
Resource allocation involves distributing system resources like CPU time, memory, and I/O devices among these processes.
Multitasking and resource allocation are interdependent. Without effective resource allocation, multitasking would lead to chaos, with processes competing for limited resources.
The Challenges of Multitasking
- Task Scheduling: Deciding which process gets CPU time and when.
- Resource Contention: Multiple processes competing for the same resource.
- Deadlock: A situation where processes are stuck waiting for resources held by each other.
Resource Allocation Mechanisms
- Memory Management
- Paging
- Physical memory is divided into fixed-size blocks called pages.
- Each process has a virtual address space mapped to these physical pages.
- Gives the illusion of a large, continuous memory space.
- Improves efficiency in memory usage.
- Segmentation
- Memory is divided into variable-sized segments (e.g. code segment, data segment).
- Each process has its own logical segments.
- Allows for logical organisation and improved memory protection.
- Virtual Memory
- Combines paging and segmentation.
- Extends RAM by using secondary storage (e.g. HDD or SSD).
- Allows processes to access more memory than physically available.
- Paging
- Device Management
- The operating system uses device drivers to communicate with specific hardware components.
- Device drivers provide a consistent method of accessing peripherals (e.g. printers, network cards).
- Device management prevents resource conflicts between processes.
- File Systems
- The file system is an abstraction layer that organises data on storage hardware into files and folders.
- Common file systems: include NTFS (Windows), APFS (macOS), and ext4 (Linux).
- Data is stored in fixed-size blocks, typically several kilobytes in size.
- The OS translates file operations (read/write) into block-level operations on the disk.
- Resource Monitoring and Limits
- The OS tracks how processes use system resources such as CPU, memory, and disk I/O.
- Limits and quotas can be applied to prevent any single process from overusing resources.
- These controls help maintain system stability and fairness across processes.
Task Scheduling: Balancing Fairness and Efficiency
Task scheduling
Task scheduling is the process of determining the order and timing of process execution.
- Fairness: Ensuring all processes get a chance to execute.
- Efficiency: Maximizing CPU utilization and minimizing wait times.
Scheduling algorithms like round robin and priority scheduling are used to balance these goals.