Operating Systems (OS) Study Guide
Introduction
An Operating System is system software that manages computer hardware and software resources,
providing common services for computer programs. It acts as an intermediary between users and
computer hardware.
OS Functions and Components
Primary Functions
1. Process Management: Create, schedule, and terminate processes
2. Memory Management: Allocate and deallocate memory space
3. File System Management: Organize and manage files and directories
4. Device Management: Control and coordinate hardware devices
5. Security and Protection: Protect system resources and user data
6. User Interface: Provide interaction between users and system
OS Structure
Kernel: Core component that manages system resources
System Calls: Interface between user programs and kernel
Device Drivers: Software that controls hardware devices
File System: Organizes and manages data storage
Shell: Command-line interface for user interaction
Process Management
Process Concepts
Process: Program in execution with associated resources
Program: Static set of instructions stored on disk
Thread: Lightweight process sharing memory space
Process Control Block (PCB): Data structure containing process information
Process States
1. New: Process is being created
2. Ready: Process is waiting to be assigned to processor
3. Running: Instructions are being executed
4. Waiting: Process is waiting for some event to occur
5. Terminated: Process has finished execution
Process Scheduling
Scheduling Objectives
Maximize CPU utilization
Maximize throughput
Minimize turnaround time
Minimize waiting time
Minimize response time
Scheduling Algorithms
Non-preemptive Algorithms
1. First Come First Serve (FCFS): Execute processes in arrival order
2. Shortest Job First (SJF): Execute shortest process first
3. Priority Scheduling: Execute highest priority process first
Preemptive Algorithms
1. Round Robin (RR): Time quantum-based scheduling
2. Shortest Remaining Time First (SRTF): Preemptive SJF
3. Preemptive Priority: Higher priority process preempts lower
4. Multilevel Queue: Separate queues for different process types
5. Multilevel Feedback Queue: Processes move between queues
Inter-Process Communication (IPC)
1. Shared Memory: Processes share memory region
2. Message Passing: Processes communicate via messages
3. Pipes: Unidirectional communication channel
4. Named Pipes (FIFOs): Persistent pipes with names
5. Sockets: Network-based communication
6. Signals: Asynchronous notifications
Synchronization and Concurrency
Critical Section Problem
Critical Section: Code segment accessing shared resources
Requirements: Mutual Exclusion, Progress, Bounded Waiting
Synchronization Mechanisms
Semaphores
Binary Semaphore: 0 or 1 value for mutual exclusion
Counting Semaphore: Non-negative integer for resource counting
Operations: P (wait/down), V (signal/up)
Monitors
High-level synchronization construct
Automatic mutual exclusion
Condition variables for waiting and signaling
Mutex (Mutual Exclusion)
Binary semaphore for critical section access
Only one thread can hold mutex at a time
Classical Synchronization Problems
1. Producer-Consumer Problem: Bounded buffer scenario
2. Readers-Writers Problem: Multiple readers, exclusive writers
3. Dining Philosophers Problem: Deadlock and starvation illustration
4. Sleeping Barber Problem: Resource management scenario
Deadlock
Necessary Conditions
1. Mutual Exclusion: Resources cannot be shared
2. Hold and Wait: Process holds resources while waiting for others
3. No Preemption: Resources cannot be forcibly taken
4. Circular Wait: Circular chain of waiting processes
Deadlock Handling Strategies
1. Prevention: Ensure at least one necessary condition never occurs
2. Avoidance: Use algorithms like Banker's algorithm
3. Detection and Recovery: Allow deadlocks, then detect and recover
4. Ignorance: Assume deadlocks won't occur (Ostrich algorithm)
Memory Management
Memory Hierarchy
1. CPU Registers: Fastest, smallest capacity
2. Cache Memory: Fast access, moderate capacity
3. Main Memory (RAM): Moderate speed, larger capacity
4. Secondary Storage: Slow access, largest capacity
Memory Allocation Techniques
Contiguous Allocation
Fixed Partitioning: Divide memory into fixed-size partitions
Dynamic Partitioning: Allocate exactly required memory
Fragmentation: Internal (fixed) vs External (dynamic)
Non-contiguous Allocation
Paging: Divide memory into fixed-size pages
Segmentation: Divide memory into variable-size segments
Segmented Paging: Combination of paging and segmentation
Virtual Memory
Concept: Illusion of having more memory than physically available
Demand Paging: Load pages only when referenced
Page Replacement: Remove pages when memory is full
Page Replacement Algorithms
1. First In First Out (FIFO): Replace oldest page
2. Least Recently Used (LRU): Replace least recently accessed page
3. Optimal: Replace page that won't be used for longest time
4. Clock Algorithm: Approximation of LRU using reference bit
Memory Protection
Base and Limit Registers: Define memory boundaries
Page Table Protection Bits: Read, write, execute permissions
Segmentation Protection: Different protection for different segments
File Systems
File System Interface
File: Named collection of related information
Directory: Container for files and other directories
Path: Location specification for files and directories
File Attributes
Name, type, location, size, protection, time stamps, user identification
File Operations
Create, delete, open, close, read, write, seek, rename
Directory Structure
1. Single-level Directory: All files in one directory
2. Two-level Directory: Separate directory for each user
3. Tree-structured Directory: Hierarchical organization
4. Acyclic Graph Directory: Shared files and directories
5. General Graph Directory: Allows cycles (links)
File System Implementation
Allocation Methods
1. Contiguous Allocation: Files occupy contiguous blocks
2. Linked Allocation: Files as linked list of blocks
3. Indexed Allocation: Index block contains pointers to data blocks
Free Space Management
1. Bit Vector: Bit map indicating free/allocated blocks
2. Linked List: Free blocks linked together
3. Grouping: Store addresses of free blocks in first free block
4. Counting: Store address and count of contiguous free blocks
Device Management
I/O Hardware
Port: Connection point for device
Bus: Set of wires for communication
Controller: Hardware component managing device
I/O Methods
1. Programmed I/O: CPU directly controls I/O operations
2. Interrupt-driven I/O: Device interrupts CPU when ready
3. Direct Memory Access (DMA): Device transfers data directly to memory
Device Drivers
Software interface between OS and hardware devices
Translate OS commands to device-specific operations
Handle interrupts and error conditions
I/O Scheduling
FCFS (First Come First Serve): Fair but may not be optimal
SSTF (Shortest Seek Time First): Minimize seek time
SCAN (Elevator): Service requests in one direction, then reverse
C-SCAN: Circular SCAN with unidirectional movement
LOOK and C-LOOK: SCAN variants that don't go to end
Security and Protection
Security Threats
1. Trojan Horse: Malicious program disguised as legitimate
2. Virus: Self-replicating malicious code
3. Worm: Standalone malicious program that spreads
4. Denial of Service: Overwhelm system resources
Protection Mechanisms
Authentication: Verify user identity
Authorization: Control access to resources
Encryption: Protect data confidentiality
Audit Trails: Log system activities
Access Control
Access Matrix: Users vs Objects permissions
Access Control Lists (ACL): Permissions for each object
Capabilities: Permissions for each user
System Calls
Types of System Calls
1. Process Control: fork(), exec(), exit(), wait()
2. File Management: open(), close(), read(), write()
3. Device Management: request(), release(), read(), write()
4. Information Maintenance: getpid(), alarm(), sleep()
5. Communication: pipe(), message queues(), shared memory()
System Call Implementation
Trap instruction transfers control to kernel
System call number identifies specific call
Parameters passed via registers or stack
Distributed Systems
Characteristics
Resource Sharing: Multiple computers share resources
Concurrency: Simultaneous execution on multiple machines
Scalability: Handle increasing workload
Fault Tolerance: Continue operation despite failures
Transparency: Hide distribution complexity from users
Distributed File Systems
Network File System (NFS): Share files across network
Andrew File System (AFS): Scalable distributed file system
Google File System (GFS): Large-scale distributed storage
Modern OS Concepts
Virtualization
Virtual Machines: Multiple OS instances on single hardware
Hypervisor: Software managing virtual machines
Container: Lightweight virtualization using shared kernel
Cloud Computing
Infrastructure as a Service (IaaS): Virtual hardware resources
Platform as a Service (PaaS): Development and deployment platform
Software as a Service (SaaS): Complete applications over internet
Mobile Operating Systems
Android: Linux-based mobile OS
iOS: Apple's mobile operating system
Challenges: Limited resources, power management, touch interface
Performance Evaluation
Performance Metrics
Throughput: Number of processes completed per time unit
Response Time: Time from request to first response
Turnaround Time: Time from submission to completion
CPU Utilization: Percentage of time CPU is busy
Evaluation Methods
1. Analytic Models: Mathematical analysis
2. Simulation: Model system behavior
3. Implementation: Measure actual system performance
Conclusion
Operating Systems are complex software that manage computer resources and provide essential services.
Understanding process management, memory management, file systems, synchronization, and security is
crucial for system programmers and administrators. Modern trends like virtualization, cloud computing,
and mobile systems continue to evolve OS design and implementation. Mastery of these concepts
provides a strong foundation for advanced systems programming and computer science careers.