Operating System Fundamentals and Core Architecture
Operating System Roles and Basic Concepts
- An Operating System (OS) manages hardware and acts as an intermediary between users and hardware, providing a foundation for application programs.
- The OS kernel is the core component loaded initially during startup; it has direct hardware access and remains resident in memory.
- The startup process involves a bootstrap program that loads the OS kernel into memory.
Hardware Components and System Structure
- Components include the CPU, main memory, secondary memory, and input/output (I/O) devices.
- The computer system includes a structured storage hierarchy and components that the OS manages.
The Importance of Studying Operating Systems
- Understanding OS helps in efficient resource management and system performance optimization.
Classification of Operating Systems
- Variants include OS-less systems, batch systems, multiprogrammed batch systems, and time-sharing systems.
- OS-less systems require manual management by programmers, which is inefficient and impractical for modern needs.
- Modern OS primarily include multiprogrammed and time-sharing systems, enhancing convenience and efficiency.
Historical Evolution of Operating Systems
Early Systems and Batch Processing [R22-R25, R27-R30]
- Early systems operated without an OS, relying on manual program loading via punch cards, which was inefficient.
- Batch systems automate program loading with a monitor, fostering batch processing though still limited.
- Single programming allows only one program at a time, leading to processor idle times.
- Multiprogramming increases CPU utilization by running multiple programs concurrently, managing multiple tasks efficiently.
Time-Sharing and Modern Computing
- Time-sharing systems enable quick response times through rapid switching among programs, facilitating user interaction.
- They are the basis of current everyday computing environments, supporting multitasking and concurrent users.
Operating System Security Mechanisms
- Multiprogramming systems pose security risks as user programs may attack the OS or other programs.
- Dual-mode protection differentiates user mode (limited privileges) from kernel mode (full privileges), enhancing system security.
- Hardware-based memory and CPU protection mechanisms, such as registers and timers, help prevent mishaps and unauthorized access.
Computer System Architectures
- Computer systems are categorized into single-processor, multiprocessor, and clustered systems, each with distinct architectures and purposes.
- Single-processor systems feature one general-purpose processor connected to main memory, executing instructions.
- Multiprocessor systems include two or more processors to improve throughput and reliability; multiprocessing types include asymmetric and symmetric approaches.
- Clustered systems consist of multiple interconnected systems sharing storage via a Storage Area Network (SAN), providing high availability and performance, often designed for high-performance computing applications.
Core Services and System Purpose
- Operating systems manage computing resources like the CPU, memory, and I/O devices, enabling program execution and resource management.
- They provide essential services for users and programs, including User Interfaces (CLI, GUI, touch-screen), program execution, file management, communication, error detection, resource allocation, accounting, and security.
- OS services also encompass resource protection, security, and error handling, ensuring secure, efficient, and dependable operations across multi-user and networked environments.
System Calls and Program Interfaces
- System calls are the fundamental interface between user applications and the kernel, providing access to privileged functions like I/O, process control, and memory management; they are typically invoked via higher-level APIs (e.g., POSIX) for portability and simplicity.
- APIs serve as wrappers around system calls, enabling developers to write portable, easier-to-understand programs that interact with the OS without directly invoking kernel functions.
- Operating systems operate in dual modes—user mode for unprivileged processes and kernel mode for privileged operations—with system calls facilitating mode transitions for executing privileged instructions safely.
- System calls are classified into types such as process control, file management, device management, information maintenance, and inter-process or network communication.
- System programs provide convenient tools for file management, system monitoring, text editing, programming, and communication; they differ from application programs, which directly serve user needs.
Process Concepts and Management {R1-R4}
- A process is defined as a program in execution, representing an independent entity consisting of program code, data, and system resources.
- Operating systems execute multiple processes, each with its own allocated resources, and may create new processes from existing ones, forming a process tree.
- Processes change states during execution, including new, ready, running, waiting, and terminated.
- The Process Control Block (PCB) maintains process-specific information like the program counter, registers, and resource allocations.
Scheduling and Context Switching {R17-R25}
- The main goal of process scheduling is to maximize CPU utilization via multiprogramming and provide user responsiveness through time-sharing, managing queues such as ready and wait queues.
- Process switching involves a context switch, which saves the current process state and loads another; overhead depends on hardware support and complexity.
- Efficiency is measured by CPU utilization, which decreases with frequent switching.
Process Creation and Termination {R26-R32}
- The operating system facilitates process creation through system calls like
fork()in UNIX, enabling parent-child process relationships. - The OS supports process termination via
exit()andabort()mechanisms that deallocate resources. - Processes may create multiple child processes, which can execute concurrently or sequentially; parent processes can wait for or terminate children as needed.
Multithreading and Scalability {R32-R37}
- Multithreading enhances application responsiveness and resource sharing; multiple threads within a process share memory and resources but have individual program counters and stacks.
- Threading is cheaper than process creation, offering benefits in scalability and efficiency.
- A distinction is made between programs (static instructions), processes (instances of executing programs), and threads (lightweight execution units sharing process resources), with real-world examples like Microsoft Word modeling these concepts.
Interprocess Communication Mechanisms {R40-R46}
- Cooperating processes share data and must communicate via IPC mechanisms such as shared memory, where processes attach shared segments to their address space.
- Message passing involves explicit
sendandreceiveoperations. - Shared memory offers faster communication but requires synchronization, whereas message passing is easier to implement, more suitable for distributed systems, and involves higher overhead due to message copying.
Chapter 4: CPU Scheduling Principles
- This section provides an analysis of CPU scheduling concepts, criteria, and various algorithms.
- It emphasizes the importance of maximizing CPU utilization through multiprogramming.
- Key scheduling decisions are made during process state transitions.
CPU-I/O Burst Cycles
- Focuses on achieving maximum CPU utilization via multiprogramming and the CPU–I/O burst cycle.
- Highlights the importance of CPU burst distribution, indicating many short bursts and fewer longer bursts.
- Describes the cycle of CPU execution and I/O wait for processes.
The CPU Scheduler and Dispatcher
- The CPU Scheduler selects processes from the ready queue and allocates CPU cores, with decisions made during specific process state changes.
- Scheduling can be either compulsory or optional depending on the process state transition.
- The Dispatcher handles the control transfer to the process selected by the CPU scheduler, involving context switching and mode changes.
- Dispatch latency is the time taken to start a new process after stopping the previous one.
Performance Metrics and Criteria
- Outlines multiple metrics such as CPU utilization, throughput, turnaround time, waiting time, and response time.
- Optimization criteria focus on maximizing CPU utilization and throughput while minimizing turnaround, waiting, and response times.
First-Come, First-Served Scheduling
- The simplest scheduling algorithm, allocating the CPU in the order processes arrive.
- Uses FIFO queues; implementation is straightforward but can lead to long average wait times.
- The convoy effect occurs when short processes wait behind long processes, impacting average waiting time.
Shortest-Job-First Scheduling
- Advances processes with the shortest next CPU burst, aiming for optimal average waiting time.
- Can be preemptive or nonpreemptive; the challenge lies in accurately predicting CPU burst lengths.
- Preemption allows more dynamic scheduling with varying process arrival and CPU burst lengths.
Priority-Based Scheduling
- Assigns the CPU to processes based on priority, with options for preemptive and nonpreemptive modes.
- Uses priorities as inverses of predicted CPU burst lengths in SJF.
- Addresses the problem of starvation, where low-priority processes might never execute; aging is proposed as a solution.
Round Robin Scheduling
- Designed for time-sharing systems, using fixed time quanta to preempt processes in a cyclic order.
- Involves quick context switches with a FIFO ready queue where processes are added at the tail.
- The length of the time quantum significantly impacts responsiveness and overhead.
Multilevel Queue and Feedback Systems
- Multilevel Queue Scheduling uses multiple queues for processes, each potentially with different scheduling algorithms and prioritization among queues.
- Multilevel Feedback Queue allows processes to move between queues based on behavior, with aging to prevent starvation.
- Scheduler parameters include the number of queues, scheduling algorithms for each, and promotion/demotion methods.
Chapter 5: Process Synchronization and Race Conditions
- Discusses the importance of process synchronization to manage concurrent processes accessing shared data.
- Covers concepts such as race conditions, the critical-section problem, and solutions including Peterson’s Algorithm, test-and-set locks, and semaphores.
- Introduces classical synchronization problems like Producer-Consumer, Readers-Writers, and Dining Philosophers.
The Critical Section Problem [R17]
- Critical sections are parts of code where shared resources are accessed, requiring mutual exclusion to prevent race conditions.
- Key requirements for solutions: mutual exclusion, progress, and bounded waiting.
- Race conditions occur when multiple processes update shared variables concurrently, leading to unpredictable results.
Synchronization Solutions and Hardware [R20, R27]
- Peterson’s Algorithm: A software-based approach utilizing shared variables to ensure mutual exclusion, assuming atomic load/store instructions.
- Test-and-set lock: A hardware primitive that atomically tests and sets a lock variable, preventing busy waiting.
- Semaphores: Integer variables and atomic operations (
waitandsignal) used to manage access to critical sections. - Semaphores can be binary (0 or 1) or counting; busy waiting wastes CPU cycles but can be improved using process blocking and wakeup queues.
Classical Synchronization Challenges [R44]
- Producer-Consumer: Involves a bounded buffer where a producer inserts data and a consumer removes data, synchronized using semaphores (mutex, empty, full).
- Readers-Writers: Multiple readers can access data simultaneously, but writers require exclusive access.
- Dining Philosophers: Philosophers alternate between thinking and eating; requires synchronization to avoid deadlock.
- Improper semaphore use can cause deadlocks; resolving strategies include resource ordering and restricting concurrent access.
Chapter 6: Deadlock Management and Prevention
Deadlock occurs when processes cannot finish execution and system resources are tied up, preventing other jobs from starting.
Deadlock Conditions and Modeling
- Deadlock arises under four necessary conditions: mutual exclusion, hold and wait, no preemption, and circular wait.
- A Resource-Allocation Graph models relationships with request and assignment edges.
- Deadlocks are identified when the graph contains cycles, especially with single-resource instances.
Strategies for Deadlock Handling
- Three strategies: prevention, avoidance, or recovery; ignoring deadlocks is also an approach.
- Deadlock Prevention: Eliminate one of the four necessary conditions (e.g., impose total ordering of resource types to prevent circular wait).
- Deadlock Avoidance: Processes declare maximum resource needs upfront; the system dynamically ensures no circular wait occurs.
- A safe state guarantees no deadlock if resource requests are granted in a sequence that satisfies all demands.
The Banker’s Algorithm
- Uses data structures like Available, Max, Allocation, and Need matrices to manage resources.
- Determines if a system state is safe by checking if processes can complete sequentially without deadlock.
- The Resource Request Algorithm checks for safety before granting requests; if granting causes an unsafe state, the process must wait.
Detection and Recovery Techniques
- Deadlock Detection: Allows deadlock to occur, then detects it using resource or wait-for graphs.
- Recovery: Processes can be terminated or resources preempted to break the deadlock.
- Process termination strategies prioritize based on process characteristics; resource preemption involves selecting victims and potential rollbacks.
Chapter 7: Main Memory Organization and Management
Credits include Silberschatz, Galvin, Gagne, Neso Academy, and Dr. Andrew LUI. This chapter discusses fundamental concepts of main memory organization.
Memory Protection and Addressing
- Programs are loaded from disk into main memory, which is a large array of addressable words or bytes.
- Logical addresses start from 0, while physical addresses are where programs are actually loaded.
- The Memory Management Unit (MMU) handles runtime address translation.
- The CPU verifies every memory access in user mode against base and limit registers to enforce protection.
Memory Allocation Strategies
- Contiguous Memory Allocation: Includes fixed-size partitions (simple but may waste memory) and variable-sized partitions (dynamically allocated based on needs).
- Dynamic Allocation Algorithms: First-fit, best-fit, and worst-fit determine how free memory holes are utilized.
- Fragmentation: Internal fragmentation occurs in fixed partitions; external fragmentation arises from scattered free blocks and can be mitigated via compaction.
Paging and Segmentation
- Paging: A non-contiguous scheme that splits processes into fixed-size pages mapped to frames, managed via page tables.
- The Translation Lookaside Buffer (TLB) enhances performance by caching recent address translations.
- Segmentation: Divides programs into logical segments (e.g., code, data), with each segment described by a table including a base address and limit.
