📑 Contents

Chapter 16.1: Operating System (OS)

9618 Computer Science - System Software

📚 Learning Objectives
📋 Prior Knowledge Required
🌟 Did You Know?

An Operating System is a program that acts as an interface between user and computer hardware and controls execution of all kinds of programs. Without an OS, a computer would be unusable - you couldn't run applications, save files, or even boot up!

USER / APPLICATIONS OPERATING SYSTEM (Kernel + System Calls) HARDWARE (CPU, Memory, I/O Devices)

1. BIOS and Bootstrap

When a computer is first powered on, it takes its start-up instructions from ROM. The computer has a Basic Input Output System (BIOS) stored in ROM, which starts a bootstrap program.

📖 Key Definitions

BIOS (Basic Input Output System): Firmware stored in ROM that performs hardware initialization during booting and provides runtime services for OS and programs.

Bootstrap Program: A small program that loads the operating system into main memory (RAM) from the Hard Disk Drive (HDD) or Solid State Drive (SSD).

Bootstrapping: The process of loading the OS into memory when the computer is switched on.

1.1 Boot Process

📝 Boot Sequence Steps
  1. Computer is powered on
  2. BIOS stored in ROM runs a bootstrap program
  3. Bootstrap loads the kernel and essential OS parts from disk into RAM
  4. OS takes control of all computer system and sets it running
  5. System is ready for user interaction
POWER ON BIOS (in ROM) BOOTSTRAP Program OS Loaded into RAM (Running)
💡 Exam Tip

Remember: BIOS is in ROM (non-volatile) and starts the bootstrap, which then loads the OS from disk (HDD/SSD) into RAM. The OS is stored on disk when computer is off!

2. Resource Management

One operating system task is to maximise utilisation of computer resources. Resource management can be split into three main areas:

📖 Three Key Resources

2.1 CPU Resource Management

Each program running on a computer is known as a process. The OS manages how software uses resources through scheduling to ensure efficient usage of CPU time.

2.2 Memory Resource Management

RAM is allocated dynamically to active programs. If RAM is full, the OS may use virtual memory on disk to simulate extra memory, allowing more programs to run.

2.3 I/O Management and DMA

I/O devices are much slower than the CPU, so the OS optimizes their use through device drivers, interrupts, and Direct Memory Access (DMA).

📖 Direct Memory Access (DMA)

A DMA controller allows hardware to access main memory independently of the CPU. This frees up the CPU to perform other tasks while slower I/O operations are taking place.

📝 How DMA Works
  1. DMA initiates the data transfer
  2. CPU carries out other tasks while transfer takes place
  3. Once transfer is complete, DMA sends an interrupt signal to the CPU
Device Typical Data Rate
Keyboard ~50 bps (bits per second)
Mouse ~120 bps
Laser Printer ~1 Mbps
Hard Disk ~100 Mbps
CPU (2.7 GHz) Billions of operations/sec

3. The Kernel

The kernel is the central component of an Operating System - the "heart" of the OS. It is responsible for communication between hardware, software, and memory.

📖 Kernel Definition

The kernel is the portion of the operating system code that is always resident in memory. It facilitates interactions between hardware and software components. When a process makes a request to the kernel, it is called a System Call.

3.1 Kernel Responsibilities

Area Responsibility
Process Management Schedules processes, allocates CPU time, handles multitasking
Memory Management Allocates RAM to processes, handles virtual memory, prevents clashes
Device Management Controls I/O devices using device drivers
Interrupt Handling Deals with interrupts from hardware (DMA, I/O devices)
File Management Handles reading/writing from files and file systems

3.2 Hiding Hardware Complexity

One of the most important tasks of an OS is to hide the complexities of hardware from users:

📝 Ways OS Hides Hardware Complexity
KERNEL SPACE Process Mgmt Memory Mgmt Device Mgmt Interrupts File System USER SPACE (Applications, Processes)

4. Multitasking and Processes

4.1 What is Multitasking?

Multitasking allows computers to carry out more than one task (process) at a time. The CPU can only execute one instruction at a time, but it processes billions per second, switching between tasks so quickly that it gives the illusion of programs running simultaneously.

📖 Key Definitions

Multitasking: Function allowing a computer to process more than one task/process at a time.

Process: A program that has started to be executed - includes program code, current data, register values, and memory space.

Scheduling: Process manager which handles removal of running programs from CPU and selection of new processes.

4.2 Types of Multitasking

Preemptive Non-Preemptive
Resources allocated for a limited time Process retains resources until completed or blocked
Process can be interrupted while running Process cannot be interrupted while running
More flexible form of scheduling More rigid form of scheduling
Examples: Round Robin, SRTF Examples: FCFS, SJF

4.3 Process Control Block (PCB)

A Process Control Block (PCB) is a data structure containing all data needed for a process to run:

📝 PCB Stores
💡 Exam Tip

The PCB is crucial for context switching - when CPU switches from one process to another, all current values must be saved in the PCB so the process can resume later!

5. Process States

A process can be in one of three states: Running, Ready, or Blocked. Understanding state transitions is crucial for understanding scheduling.

State Description Characteristics
Running Process is being executed by the processor Only ONE process can be running at a time
Ready Process is prepared to run but waiting for CPU New processes always start in ready state
Blocked Process is waiting for an event or resource e.g., waiting for I/O completion
READY RUNNING BLOCKED TERMINATED NEW PROCESS PCB created Dispatched Interrupt/ Time slice I/O request I/O complete Complete
⚠️ Important: State Transitions

6. Scheduling Algorithms

Scheduling decides which processes should be carried out and for how long. Different algorithms have different uses, benefits, and drawbacks.

6.1 First Come First Served (FCFS)

📖 FCFS Algorithm

Non-preemptive algorithm using FIFO (First In First Out) principle. Jobs are executed in the order they arrive.

📝 FCFS Characteristics

6.2 Shortest Job First (SJF)

📖 SJF Algorithm

Non-preemptive algorithm that prioritizes the shortest job in the queue. Process requiring least CPU time is executed first.

📝 SJF Characteristics

6.3 Shortest Remaining Time First (SRTF)

📖 SRTF Algorithm

Preemptive version of SJF. When a process with shorter burst time arrives, the existing process is removed and the shorter one executes.

6.4 Round Robin (RR)

📖 Round Robin Algorithm

Preemptive algorithm that allocates a fixed time quantum to each process. Processes are served in circular order.

📝 Round Robin Characteristics

6.5 Scheduling Algorithm Comparison

Algorithm Benefits Drawbacks
Round Robin Fair share of CPU; Good for time-sharing; Predictable Choosing quantum is difficult; High turnaround for long processes
FCFS Simple and easy to understand; Fair order Poor performance if long process arrives first; High waiting time
SJF Minimizes waiting time; Efficient for short processes Requires burst time in advance; Long processes may starve
SRTF Ideal for shorter burst times; Preemptive flexibility Requires burst time; High context switching overhead
💡 Exam Tip - Calculations

Turnaround Time = Completion time - Arrival time

Waiting Time = Turnaround time - Burst time

Average Waiting Time = Total waiting time / Number of processes

6.6 Objectives of Scheduling

📝 Scheduling Objectives

6.7 Process Priority

Process priority depends on:

📖 Priority Factors

7. Interrupt Handling

An interrupt is a signal sent to the processor by hardware or software indicating that they require processor attention.

📖 Types of Interrupts

7.1 Interrupt Handling Process

📝 Interrupt Handling Steps
  1. Interrupt signal occurs (keyboard input, DMA completion, timer)
  2. Current process is paused and its state is saved (registers, PC)
  3. Kernel identifies the source and priority of interrupt
  4. Appropriate Interrupt Service Routine (ISR) is called
  5. Once complete, original process is restored and resumed

7.2 Interrupt Priority Levels (IPL)

IPL Level Interrupt Type
31 Power fail interrupt (highest priority)
24 Clock interrupt
20-23 I/O devices
📖 Key Terms

Interrupt Dispatch Table (IDT): Data structure linking device descriptions with appropriate interrupt routines.

Interrupt Service Routine (ISR): Program code that handles the interrupt event.

7.3 Interrupts and Scheduling

Interrupt Type Scheduling Role
Timer Interrupts Triggers context switch between processes (preemptive multitasking)
I/O Interrupts Signals I/O task completion - unblocks waiting processes
Hardware Interrupts Responds to urgent external events (power failure, input)
Software Interrupts Requests system-level services (memory allocation)

8. Memory Management

Memory management deals with allocation and deallocation of primary memory. When a process starts, memory is allocated; when completed, memory is deallocated.

📖 Benefits of Memory Management

8.1 Memory Management Methods

📝 Three Methods
  1. Single (Contiguous) Allocation: All memory to one application - inefficient
  2. Paging: Memory divided into fixed-size blocks (pages/frames)
  3. Segmentation: Memory divided into variable-size segments

8.2 Paging

Paging divides main memory into equal-sized blocks called frames, and processes into equal-sized pages.

📖 Paging Characteristics
📝 Page Table Contains

9. Segmentation

Segmentation divides memory into variable-size blocks called segments. Each segment corresponds to different types of data (e.g., code segment, data segment, stack segment).

📖 Segmentation Characteristics

9.1 Paging vs Segmentation

Aspect Paging Segmentation
Block Size Fixed-size blocks Variable-size blocks
Fragmentation Internal fragmentation (unused space in page) External fragmentation (gaps between segments)
User Knowledge Invisible to user Visible to programmer
Address Single value (page number) Two values (segment number + offset)
Speed Faster access Slower access
Managed By Operating System Compiler calculates segment size
💡 Exam Tip

Internal Fragmentation: Wasted space INSIDE a block (paging)

External Fragmentation: Wasted space OUTSIDE blocks (segmentation)

10. Virtual Memory

Virtual memory uses secondary storage (HDD/SSD) to extend RAM, giving the illusion of more memory than physically available.

📖 Virtual Memory Definition

Secondary storage is used to extend RAM so the CPU appears to access more memory space than available. Only data in use needs to be in main memory - other data can be swapped between RAM and virtual memory.

📝 How Virtual Memory Works
  1. When RAM is full, OS moves less-used pages to disk (swap space)
  2. When that data is needed again, it's swapped back into RAM
  3. This gives illusion of unlimited memory
  4. Implemented using demand paging

10.1 Virtual Memory Benefits & Drawbacks

Benefits Drawbacks
Run larger programs than RAM allows Slower than physical RAM
More programs can run simultaneously Increased disk read/write operations
Cost savings (less RAM needed) Can lead to disk thrashing
Data sharing between RAM and virtual memory Complex algorithm implementation

10.2 Page Fault

A page fault occurs when a process needs access to a page that is not in memory. The required page must be swapped in from secondary storage.

11. Disk Thrashing & Page Replacement

11.1 Disk Thrashing

⚠️ Disk Thrashing

When more time is spent moving pages in and out of memory than actually processing, system performance degrades severely. This can lead to thrash point where execution halts.

📝 Reducing Disk Thrashing

11.2 Page Replacement Algorithms

When a page fault occurs and memory is full, a page must be replaced. Different algorithms decide which page to remove:

Algorithm Description Pros/Cons
FIFO Remove oldest page in memory Simple but may suffer Belady's anomaly
LRU Remove least recently used page Often most efficient, requires tracking
Optimal Remove page used farthest in future Best efficiency but impossible to implement (needs future knowledge)
📖 Belady's Anomaly

Unexpected phenomenon where increasing number of frames can actually increase page faults in FIFO algorithm.

12. Key Takeaways

📌 Summary Points

Operating System Basics

Resource Management

Process Management

Memory Management

13. Exam-Style Questions

1. Explain what is meant by virtual memory. [3 marks]

Answer:

  • Secondary storage (disk) is used to extend the RAM
  • CPU appears to access more memory space than available RAM
  • Only data in use needs to be in main memory, so data can be swapped between RAM and virtual memory
  • Virtual memory is created temporarily on disk
  • Additional point: Implemented using demand paging
2. State one difference between paging and segmentation in the way memory is divided. [1 mark]

Answer (any one):

  • Paging divides memory into fixed-size blocks; Segmentation divides into variable-size blocks
  • OS divides memory into pages; Compiler is responsible for segment size
  • Access times for paging is faster than for segmentation
3. Describe how the operating system hides the complexities of hardware from users. [4 marks]

Answer:

  • Using GUI interfaces rather than CLI (drag-and-drop instead of commands)
  • Using device drivers which simplify complexity of hardware interfaces
  • Simplifying saving and retrieving data from memory and storage devices
  • Carrying out background utilities (virus scanning, updates)
  • Additional: Provides abstraction layer between applications and hardware
4. Explain the purpose of Direct Memory Access (DMA) and how it works. [4 marks]

Answer:

  • DMA allows hardware to access main memory independently of the CPU
  • DMA initiates the data transfer between I/O devices and memory
  • CPU is free to carry out other tasks while transfer takes place
  • Once transfer is complete, DMA sends an interrupt signal to CPU
  • Additional: Frees up CPU for processing instead of data movement
5. Describe the three states a process can be in and explain the transitions between them. [6 marks]

Answer:

  • Running: Process is being executed by CPU (only one at a time)
  • Ready: Process is prepared to run but waiting for CPU availability
  • Blocked: Process is waiting for an event or resource (e.g., I/O)
  • Ready → Running: Process is dispatched by scheduler
  • Running → Ready: Interrupt or time slice expired
  • Running → Blocked: Process needs I/O or resource
  • Blocked → Ready: Event or resource becomes available
6. Compare Round Robin and First Come First Served scheduling algorithms. [4 marks]

Answer:

  • Round Robin: Preemptive; each process gets equal time quantum; fair share of CPU; good for time-sharing systems
  • FCFS: Non-preemptive; processes executed in arrival order; simple to implement; high average waiting time
  • Round Robin prevents starvation; FCFS can have long waits if long process arrives first
  • Round Robin involves more context switching; FCFS has less overhead
  • Additional: RR performance depends on quantum size; FCFS is less flexible
7. What is the role of the kernel in an operating system? [5 marks]

Answer:

  • Kernel is the core component of OS, always resident in memory
  • Process Management: Schedules processes, allocates CPU time
  • Memory Management: Allocates RAM, handles virtual memory
  • Device Management: Controls I/O devices via drivers
  • Interrupt Handling: Deals with hardware interrupts
  • Additional: Facilitates communication between hardware and software
8. Explain what is meant by disk thrashing and how it can be reduced. [4 marks]

Answer:

  • Disk thrashing occurs when excessive swapping in and out of pages happens
  • More time is spent moving pages than actually processing
  • Can lead to system slowdown or complete halt (thrash point)
  • Can be reduced by: installing more RAM, reducing running programs, reducing swap file size
  • Additional: Caused by insufficient memory for running processes
9. Describe the boot process when a computer is switched on. [5 marks]

Answer:

  • Computer is powered on
  • BIOS stored in ROM runs a bootstrap program
  • Bootstrap loads the kernel from HDD/SSD into RAM
  • OS takes control of computer system
  • System is ready for user interaction
  • Additional: OS provides interface between user and hardware
10. What is a Process Control Block (PCB) and what information does it store? [5 marks]

Answer:

  • PCB is a data structure containing all data needed for a process to run
  • Stores: Current process state (ready, running, blocked)
  • Process privileges and Process ID
  • Register values (PC, MAR, MDR, ACC)
  • Process priority and scheduling information
  • Memory management information (page/segment tables)
  • Additional: Created when process starts, essential for context switching

14. Glossary

Term Definition
BIOS Basic Input Output System - firmware in ROM that initializes hardware during boot
Bootstrap Small program that loads the OS into memory from disk
Blocked State Process waiting for an event or resource (e.g., I/O completion)
Burst Time Time when a process has control of the CPU
Context Switch Saving state of one process and loading another
DMA Direct Memory Access - allows hardware to access memory without CPU
Frames Fixed-size physical memory blocks in paging
Internal Fragmentation Unused space inside allocated memory block (paging)
External Fragmentation Unused space between allocated blocks (segmentation)
Interrupt Signal to CPU requiring immediate attention
Kernel Core component of OS, always resident in memory
Multitasking Ability to handle multiple processes simultaneously
Page Fault Occurs when required page is not in memory
Pages Fixed-size logical memory blocks in paging
PCB Process Control Block - data structure for process information
Process A program that has started to be executed
Quantum Fixed time slice allocated to a process
Ready State Process prepared to run but waiting for CPU
Running State Process currently being executed by CPU
Scheduling Deciding which process runs and for how long
Segmentation Memory management with variable-size blocks
Virtual Memory Using disk space to extend available RAM

15. Exam Success Tips

💡 Process States - Key Points
💡 Scheduling Algorithms - Remember
🧠 Memory Trick: Paging vs Segmentation
❌ Common Mistakes to Avoid

15. Exam Success Tips (Continued)

💡 Answer Structure Tips
🌟 Quick Reference
Topic Key Point
BIOS In ROM, starts bootstrap
Kernel Always in memory, manages resources
DMA Transfers data without CPU involvement
PCB Stores process state and information
Virtual Memory Extends RAM using disk
Page Fault Page not in memory
Disk Thrashing Excessive page swapping
📌 Final Exam Reminders