A1.3 Operating Systems
THEME A: SYSTEM FUNDAMENTALS
Topic Overview
A1.3: Operating Systems and Control Systems.
An operating system (OS) is system software that acts as an intermediary between users, application software, and computer hardware. It manages resources, provides a platform for applications, and ensures system efficiency and security.
Table of Contents
1. Role of an Operating System
- Resource Management: Manages CPU, memory, storage, and I/O devices.
- Platform: Provides a stable base for application software.
- User Interface: Offers GUI or CLI for interaction.
- Security & Stability: Ensures system integrity and efficiency.
Abstraction
The OS hides complex hardware details, offering simple interfaces (files, folders) like a car dashboard hides the engine mechanics.
2. Functions of an Operating System
Process Management
Manages creation, termination, and tracking of processes.
States: New, Ready, Running, Blocked, Terminated.
Memory Management
Allocates RAM, protects process memory, and manages Virtual Memory (Paging/Swapping).
File System
Organizes data into files/directories and manages access permissions.
Security
User authentication, firewalls, and data encryption (CIA Tuple).
3. Approaches to CPU Scheduling
Table 1: Scheduling Approaches
| Scheduling Approach | Definition |
|---|---|
| First-Come, First-Served (FCFS) | A non-pre-emptive scheduling algorithm where processes are allocated CPU time in the order they arrive in the ready queue. Once a process starts execution, it runs to completion before the next process is scheduled. The primary scheduling criterion is arrival time. |
| Shortest Job First (SJF) | A non-pre-emptive or pre-emptive (Shortest Remaining Time First) algorithm that selects the process with the smallest execution time. It minimizes waiting time but requires knowing the burst time in advance. |
| First-Come, First-Served (FCFS) | A non-pre-emptive scheduling algorithm where processes are allocated CPU time in the order they arrive in the ready queue. Once a process starts execution, it runs to completion before the next process is scheduled. The primary scheduling criterion is arrival time. |
| Round Robin | A pre-emptive scheduling algorithm designed to ensure fair CPU sharing. Each process is given a fixed time slice (quantum). If a process does not complete within its quantum, it is pre-empted and placed at the back of the ready queue. |
| Multilevel Queue Scheduling | The ready queue is divided into multiple separate queues, each with its own priority level and scheduling algorithm. Processes are permanently assigned to a queue based on type (e.g., system vs. user). Scheduling between queues may use fixed priority. |
| Priority Scheduling | Each process is assigned a priority, and the CPU is allocated to the process with the highest priority. Can be pre-emptive (interrupts running process) or non-pre-emptive (waits for current process to finish). |
Table 2: Key Scheduling Terminology
| Term | Definition |
|---|---|
| Slice / Quantum | A fixed time interval allocated to a process in a pre-emptive system (e.g., Round Robin). |
| Pre-emption | The OS interrupts a currently running process to allocate CPU time to another (higher priority) process. |
| Fairness | Ensuring all processes receive an equitable share of CPU time and a reasonable opportunity to execute. |
| Starvation | A condition where a low-priority process is indefinitely denied CPU time because other processes take precedence. |
| Efficiency | Maximizing CPU utilization (throughput) while minimizing waiting time. |
Table 3: Comparison of Scheduling Types
| Comparator | FCFS | Round Robin | Priority |
|---|---|---|---|
| Fairness & Starvation | Fair in arrival order. Convoy Effect (short wait for long). | Fair (equal quantum). Depends on quantum size. | High risk of Starvation for low priority. Needs Aging. |
| Efficiency | Least efficient for mixed tasks. | High overhead due to Context Switching. | Efficient if priorities correct. |
Table 4: Use Cases
| Algorithm | Typical Use Case |
|---|---|
| FCFS | Simple systems where predictability > speed (Batch processing). |
| SJF | Batch systems where job times are known in advance. Minimizes average wait time. |
| Round Robin | Time-sharing / Multitasking systems (Desktop OS) requiring responsiveness. |
| Multilevel Queue | Complex OS managing different process types (System vs User). |
| Priority | Real-time systems (e.g., Hospital monitors, flight control). |
IB Exam Tip
Exam questions often ask to "Compare" or "Describe". Use Keywords for full marks: Pre-emptive, Non-pre-emptive, Quantum, Starvation, Fairness, Context Switching. A 2-3 sentence explanation using these terms is usually sufficient.
4. Interrupts & Polling
What is an Interrupt?
An interrupt is a signal sent to the CPU that temporarily halts the current task so that a more urgent process (the "interrupt handler") can be addressed. It allows the OS to multitask and respond quickly to events.
Types of Interrupts:
- Hardware Interrupts: Generated by external devices (e.g., Keyboard press, Printer out of paper, Mouse move).
- Software Interrupts: Triggered by apps or the OS (e.g., Divide-by-zero error, Crash, System call).
- Timer Interrupts: Periodic signals to trigger multitasking (switching processes).
How Interrupts Work
- IRQ Sent: Device/Software sends an Interrupt Request to the CPU.
- Priority Check: CPU checks if the interrupt priority is higher than the current task.
- Save Status: If higher, CPU saves the current task's state (Registers & Program Counter) onto the Stack.
- Execute ISR: CPU runs the Interrupt Service Routine (ISR) to handle the event.
- Restore: Once done, CPU restores the saved state from the Stack and resumes the original task.
The Role of Buffers
Buffers are temporary memory areas used to store data when there is a speed mismatch between devices (e.g., fast CPU vs. slow Printer). Interrupts and Buffers work together efficiently.
Example: Streaming Video
Data downloads into a buffer. If the internet is slow, the video plays from the buffer to prevent freezing (buffering).
Example: Printing
CPU dumps document data into a buffer and goes back to work. The printer reads from the buffer. If empty or jammed, it sends an Interrupt.
Spooling vs Buffering
🔹 Spooling
Stands for: Simultaneous Peripheral Operations On-Line
- Storage used: Disk (secondary memory)
- Purpose: Handle very slow I/O devices
- Works with: Multiple jobs queued
- Example: Print queue 🖨️
- Nature: Jobs are processed one by one
🔹 Buffering
Temporary storage area in RAM
- Storage used: Main memory (RAM)
- Purpose: Match speed difference between producer & consumer
- Works with: Continuous data flow
- Example: Video/audio streaming 🎧📺
- Nature: Data is processed in chunks
📊 Side-by-side Comparison
| Feature | Spooling | Buffering |
|---|---|---|
| Storage | Disk | RAM |
| Device speed | Very slow (printer) | Faster devices |
| Queue | Yes (job queue) | Temporary data area |
| Multitasking | Yes | Limited |
| Data handling | Whole jobs | Small blocks |
| Typical example | Printing | Streaming, keyboard input |
🧠 Key Difference
Spooling queues entire jobs on disk for slow devices, while buffering temporarily holds data in RAM to smooth speed differences.
Why are Interrupts Needed? (Exam Keywords)
- Allow Multitasking (Time-slicing).
- Avoid inefficient Polling (constant checking).
- Handle time-sensitive requests immediately.
- Efficient use of hardware (CPU doesn't wait).
- Handle errors (e.g., Printer jams).
Polling vs Interrupts
| Feature | Polling | Interrupts |
|---|---|---|
| Mechanism | CPU actively checks devices ("Ready?") | Devices signal CPU ("I need you!") |
| CPU Efficiency | Low (Wastes cycles checking) | High (Only acts when needed) |
| Complexity | Simple to implement | Complex hardware/software |
| Security Risk | Vulnerable to blind spots between checks | Vulnerable to DoS attacks (Interrupt Storms) |
Exam Scenario: Engine Control Unit (ECU)
**Scenario**: An automotive company is designing an **ECU** that processes sensor data continuously.
| Interrupt Source | Priority | Response Time |
|---|---|---|
| Engine Temperature | 1 (Highest) | < 5 ms |
| Fuel Injection | 2 | < 10 ms |
| Speed Sensor | 3 | < 20 ms |
| Dashboard Display | 4 (Lowest) | < 100 ms |
Q1. Handling Simultaneous Interrupts [6 marks]
If multiple interrupts occur simultaneously (e.g., Engine Temp and Dashboard), the CPU compares their Priority Levels.
1. The Engine Temperature (Priority 1) is handled first because it is critical to prevent engine failure.
2. Lower priority interrupts (Dashboard) are placed in a Queue or remain pending until the higher priority ISR completes.
3. If a lower priority task is running and a higher one arrives, the CPU Pre-empts (interrupts) the lower one, saves its state to the Stack, and switches to the higher priority immediately.
Q2. Mechanism for Critical Tasks [4 marks]
The mechanism ensures critical tasks are not delayed through Pre-emptive Scheduling and Nested Interrupts.
• When a critical interrupt (Fuel Injection) arrives, the current non-critical task (Speed Sensor) is paused.
• The specific Interrupt Service Routine (ISR) for the critical task is prioritized in the Interrupt Vector Table.
• Once the critical task is done, the CPU restores the previous task from the stack, ensuring high-priority deadlines (< 10ms) are always met.
5. Multitasking & Resource Allocation
Role in Multitasking
Multitasking is the ability of the OS to execute multiple processes "simultaneously" by rapidly switching the CPU between them (Context Switching).
Context Switching
The OS saves the state of the current process (registers, PC) and loads the next one. This happens in microseconds.
Scheduling
Decides which process runs next to balance fairness, responsiveness, and efficiency.
Role in Resource Allocation
The OS distributes limited resources (CPU, RAM, I/O) among competing processes securely and efficiently.
Paging, Virtual Memory, and Segmentation prevent crashes and allow efficient RAM usage.
Uses drivers and queues to prevent conflicting access to hardware (e.g. printers).
Controls permissions and organizes data to prevent corruption.
Enforces quotas and monitors activity to prevent monopolization.
The Concept of Deadlock
**Deadlock** is a situation in computing where two or more processes are unable to proceed because each is waiting for the other to release a resource. It is a permanent blocking of a set of processes.
Imagine philosophers sitting at a round table with one fork between each pair. To eat, a philosopher needs two forks (left and right). If every philosopher picks up their left fork simultaneously, no one can pick up a right fork. Everyone waits forever. This is deadlock.
Conditions for Deadlock (Coffman Conditions):
- Mutual Exclusion: Resources cannot be shared (e.g., a printer).
- Hold and Wait: A process holding a resource is waiting for another.
- No Pre-emption: Resources cannot be forcibly taken away.
- Circular Wait: A cycle of dependencies exists (A waits for B, B waits for A).
6. Control Systems
A control system manages commands or regulates the behavior of other devices.
Open-Loop
No feedback. Does not adjust based on results.
Example: Microwave Timer
Closed-Loop
Uses Feedback to self-correct.
Example: Thermostat / Cruise Control
Real-Time Control Systems
Real-time systems must generate correct responses within a specific time constraint (deadline).
| Feature | Hard Real-Time | Soft Real-Time |
|---|---|---|
| Definition | Must meet deadline ALWAYS. | Aim to meet deadline. |
| Consequence of Failure | Catastrophic / System Failure. | Degraded Performance / Annoyance. |
| Examples | Airbags, Pacemakers, Flight Control. | Video Streaming, Online Gaming. |
Components
Exam Summary
An OS acts as an intermediary, managing resources (CPU, Memory, I/O) and ensuring security. It enables multitasking via scheduling and interrupts. Control Systems use sensors, controllers, and actuators (often with feedback) to automate real-world tasks.
7. Application Software (Topic 2.3)
System vs. Application Software
Software designed to run the computer's hardware and application programs. It provides the platform.
- OS: Windows, macOS, Linux.
- Drivers: Printer driver, Graphics driver.
- Utilities: Antivirus, Disk Defragmenter.
Software designed for the user to perform specific tasks or activities.
- Productivity: Word, Excel.
- Creative: Photoshop, CAD.
- Communication: Zoom, Chrome.
Common Application Types
Word Processors
Used for creating, editing, and formatting text documents.
Ex: Microsoft Word, Google Docs, Pages.
Spreadsheets
Organize data in rows/columns for calculation and analysis.
Ex: Microsoft Excel, Google Sheets.
DBMS (Database Management Systems)
Software to create and manage databases (tables, queries, reports).
Ex: Microsoft Access, MySQL, FileMaker.
Email Clients
Send, receive, and organize emails.
Ex: Outlook, Apple Mail, Gmail (Web).
Web Browsers
Retrieve and display content from the World Wide Web.
Ex: Chrome, Safari, Firefox.
CAD (Computer Aided Design)
Create precise 2D/3D technical drawings and models.
Ex: AutoCAD, SolidWorks.
Graphic Processing
Manipulate visual images (photos, vectors).
Ex: Adobe Photoshop, Canva.
Common Interface Features (GUI)
Most modern applications use a **GUI (Graphical User Interface)** involving WIMP (Windows, Icons, Menus, Pointers).
Row of icons/buttons for frequent actions (Save, Print, Bold).
List of commands organized by category (File, Edit, View).
Temporary window requesting user input (e.g., "Save Changes?").