Definition
An Operating System is fundamentally a resource manager. Its primary function is to manage all hardware and software resources of a computer system (CPU, memory, I/O devices, files, etc.) and allocate them fairly and efficiently among competing processes and users. The OS ensures optimal utilization of resources while maintaining system stability and fairness.
Key Resources Managed by Operating System
1. CPU (Central Processing Unit / Processor)
What is it? The “brain” of the computer that executes instructions. Only one instruction can execute at a time on single-core processor.
OS Management Functions:
- Scheduling: Decide which process gets CPU next
- Time Allocation: Decide how long each process runs
- Context Switching: Switch between processes
- Preemption: Force a process to give up CPU
- Load Balancing: Distribute work across multiple CPUs (if available)
Goals:
- Maximize CPU utilization (keep CPU busy)
- Minimize response time (quick response to user)
- Ensure fairness (all processes get CPU time)
- Meet deadlines (for real-time systems)
Scheduling Algorithms:
- FCFS (First Come First Served)
- SJF (Shortest Job First)
- Round Robin
- Priority Scheduling
- Multilevel Feedback Queue
2. Memory (RAM)
What is it? Fast storage where currently running programs and data reside. Much faster than disk but limited in size.
OS Management Functions:
- Allocation: Give memory to processes
- Deallocation: Free memory when process finishes
- Protection: Prevent processes from interfering
- Virtual Memory: Use disk as extension of RAM
- Paging/Swapping: Move data between RAM and disk
Goals:
- Efficient memory use (minimize waste)
- Support multiple processes
- Provide memory protection (isolation)
- Enable process sharing when appropriate
Management Techniques:
- Base and limit registers (protection)
- Paging (divide memory into pages)
- Segmentation (divide into segments)
- Virtual memory (illusion of unlimited memory)
3. Input/Output (I/O) Devices
What are they? Hardware devices for input (keyboard, mouse, network) and output (monitor, printer, disk, speakers).
OS Management Functions:
- Device Control: Control device operation
- I/O Scheduling: Queue requests and process fairly
- Device Drivers: Software to communicate with devices
- Interrupt Handling: Respond to device signals
- Buffering: Temporary storage for data transfer
- Device Independence: Shield programs from device details
Common Devices:
- Storage: Disk drives (HDD, SSD), USB drives
- Input: Keyboard, mouse, touchscreen, microphone
- Output: Monitor, printer, speakers
- Network: Network interface cards
- Specialty: Scanners, cameras, sensors
Goals:
- Fairness (all processes get fair access)
- Efficiency (minimize device idle time)
- Reliability (data not corrupted)
- Protection (control access)
4. File System
What is it? Organized storage of data on disk in files and directories.
OS Management Functions:
- File Operations: Create, read, write, delete files
- Directory Management: Organize files hierarchically
- Access Control: Manage file permissions
- Storage Allocation: Decide where file data stored on disk
- File Protection: Backup and recovery
Goals:
- Easy file access
- Efficient storage use
- Data protection
- Reliable persistence
5. Network Resources
What are they? Network interfaces and communication channels.
OS Management Functions:
- Network Interface Management: Control network cards
- Protocol Management: Handle TCP/IP, etc.
- Bandwidth Allocation: Share network capacity
- Connection Management: Establish connections
Resource Allocation Strategies
1. Request-Based Allocation
How it works:
- Process requests a resource
- OS checks if available
- If available: allocate immediately
- If unavailable: place in queue
Characteristics:
- Simple mechanism
- Queue-based fairness
- May cause starvation (if always other requests ahead)
Example: Process needs memory
- OS checks if enough free memory
- If yes: allocates to process
- If no: waits in queue for other process to free memory
2. Preemptive Allocation
How it works:
- OS can take resource from one process
- Allocate to another higher-priority process
- Return to first process later
Characteristics:
- Resource can be interrupted
- Supports priorities
- Complex to implement
Used for: CPU time primarily
Example: High priority process arrives
- Currently running medium priority process
- OS can take CPU from medium and give to high
- Medium process resumes later
3. Non-Preemptive Allocation
How it works:
- Resource allocated to process
- Cannot be taken away until process releases it
- Process keeps until completion
Characteristics:
- Once allocated, cannot interrupt
- Simpler to implement
- May lead to low utilization
Used for: Locks, I/O devices
Example: Process acquires printer
- No other process can use printer
- Must wait until first process releases it
- No interruption possible
Performance Objectives and Tradeoffs
CPU Scheduling Objectives
1. Throughput
- Number of jobs/processes completed per unit time
- Higher is better
- Maximize work done
2. Turnaround Time
- Time from job submission to completion
- Lower is better
- Important for batch processing
Example: Submit job at 9:00 AM, get results at 10:00 AM
- Turnaround time = 1 hour
3. Response Time
- Time from request to first response
- Lower is better
- Important for interactive systems
Example: Type command, see result in 0.1 seconds
- Response time = 0.1 seconds
4. CPU Utilization
- Percentage of time CPU is busy
- Higher is better (up to ~85-90%)
- Idle CPU wastes resources
5. Fairness
- All processes get fair CPU time
- No process starves
- Important for multi-user systems
Tradeoffs:
- Short response time may reduce throughput
- High utilization may increase response time
- Fairness may reduce throughput
Resource Conflicts and Solutions
1. Competition for Resources
Problem: Multiple processes want same resource simultaneously
Example: Three processes want printer at same time
Solutions:
a) Queuing
- Place requests in queue
- Process one at a time (FCFS)
- Fair but slow
b) Scheduling
- Use scheduling algorithm
- May not be strictly FCFS
- Can prioritize
c) Priorities
- Important processes go first
- Less fair but better performance
- Used in real-time systems
2. Deadlock
Definition: Circular wait where processes hold resources and wait for each other indefinitely.
Example:
- Process A has printer, wants disk
- Process B has disk, wants printer
- Both wait forever!
Solutions:
- Deadlock prevention (design to avoid)
- Deadlock avoidance (prevent at runtime)
- Deadlock detection and recovery (detect and fix)
3. Starvation
Definition: Process never gets resource despite waiting
Example:
- Process A waiting for printer
- Short processes keep coming
- Process A never gets turn
Solutions:
- Aging: Increase priority over time
- Guaranteed Minimum: Give minimum allocation
- Fair Scheduling: Ensure all get chance
Resource Protection and Isolation
1. Memory Protection
Goal: Prevent process from accessing memory outside its allocated area
Mechanisms:
- Base and Limit Registers: Define memory bounds
- Virtual Memory: Each process has own address space
- Page Protection: Mark pages as read-only, execute-only
- Segmentation: Divide memory into protected segments
Example:
- Process A allocated memory 1000-2000
- Process A tries to access 3000
- Hardware raises exception
- OS terminates process A
- Other processes protected
2. Device Protection
Goal: Prevent unauthorized device access
Mechanisms:
- Privileged Instructions: Only OS can directly control devices
- Device Drivers: OS-controlled interface
- Access Control Lists: Who can use device
- Interrupt Handlers: OS-controlled interrupts
3. File System Protection
Goal: Control file access
Mechanisms:
- File Permissions: Read, write, execute for owner, group, others
- User Authentication: Password/login
- Encryption: Scramble sensitive data
- Audit Trails: Log who accessed what
Evaluation Metrics
Resource Utilization
$$Utilization = \frac{Time\ resource\ in\ use}{Total\ time} \times 100\%$$
Examples:
- CPU utilization 80% = CPU busy 80% of time
- Disk utilization 60% = Disk busy 60% of time
- Memory utilization 70% = 70% of RAM in use
Throughput
$$Throughput = \frac{Number\ of\ jobs\ completed}{Total\ time}$$
Examples:
- CPU throughput: 50 jobs/hour
- Disk throughput: 100 MB/second
- Network throughput: 100 Mbps
Turnaround Time
$$Turnaround\ Time = Completion\ Time - Submission\ Time$$
Example:
- Submitted: 9:00 AM
- Completed: 5:00 PM
- Turnaround = 8 hours
Average Response Time
$$Avg\ Response\ Time = \frac{\sum (Time\ to\ first\ response)}{Number\ of\ requests}$$
Example:
- Request 1: 0.2 seconds response
- Request 2: 0.3 seconds response
- Request 3: 0.1 seconds response
- Average = 0.2 seconds
Resource Monitoring and Management
System Monitoring Tools
Available on all operating systems:
- Task Manager (Windows): View CPU, memory, disk usage
- Activity Monitor (macOS): Similar to Task Manager
- Top/htop (Linux): Command-line resource monitor
- Performance Monitor: Detailed metrics
Metrics Monitored
- CPU usage percentage per process
- Memory (RAM) usage
- Disk I/O rate (reads/writes per second)
- Network bandwidth usage
- Number of running processes
- File handles open
- Thread count
Resource Allocation Policies
Allocation Policies
1. Optimal Allocation
- Goal: Maximize system performance
- Allocate to best use
- Requires knowing future needs (difficult!)
2. Fair Share Allocation
- Equal allocation to all processes
- Simple and fair
- May not be optimal
3. Need-Based Allocation
- Allocate based on process requirements
- More complex
- Better matching
4. Priority-Based Allocation
- Important tasks get more
- Unfair to low-priority
- Better throughput
Resource Limits
Hard Limits (Physical)
Cannot exceed:
- Total memory installed
- Total disk capacity
- Number of CPU cores
- Network bandwidth
Soft Limits (Configurable)
Can be changed by administrator:
- Max memory per process (e.g., 2 GB)
- Max open files per user (e.g., 1000)
- Max processes per user (e.g., 100)
- Max disk quota per user (e.g., 10 GB)
Dynamic Resource Management
1. Predictive Allocation
- Anticipate future needs
- Pre-allocate resources
- Reduce latency
2. Adaptive Allocation
- Monitor current usage
- Adjust allocation dynamically
- Optimize for current load
3. Oversubscription
- Allocate more than physical resources
- Works if not all used simultaneously
- Common in cloud computing
Modern Resource Management
Containers and Virtualization
Virtual Machines:
- Allocate portion of computer resources to VM
- VM sees virtual CPU, memory, disk
- OS inside VM manages those resources
Containers:
- Lighter-weight than VMs
- Allocate specific resource limits
- Process sees limited resources
Cloud Resource Management
Auto-scaling:
- Monitor resource usage
- Automatically add/remove resources
- Meet demand elastically
Load Balancing:
- Distribute requests across servers
- Prevent overload on single server
- Maximize utilization
Exam Important Points
- Define OS as resource manager
- Major resources (CPU, memory, I/O, files, network)
- OS management functions for each resource
- Allocation strategies (request-based, preemptive, non-preemptive)
- Performance objectives (throughput, response time, utilization)
- Resource conflicts (competition, deadlock, starvation)
- Solutions to conflicts
- Protection and isolation mechanisms
- Performance metrics and formulas
- Monitoring and management tools