Operating Systems
Complete Notes
Processes · Memory Management · File Systems · Scheduling · Synchronization · All in Easy English
Operating Systems Basics
Introduction to OS Concepts and Functions
What is an Operating System?
An Operating System (OS) is system software that manages hardware resources and provides services to applications. It acts as an intermediary between users and hardware.
Main Functions of OS
- Resource Management: CPU, Memory, Disk, I/O devices
- Process Management: Create, schedule, terminate processes
- Memory Management: Allocate and manage RAM
- File Management: Organize and manage files
- Security: Protect system from unauthorized access
- User Interface: Command-line or graphical interface
Types of Operating Systems
| Type | Characteristics | Examples |
|---|---|---|
| Batch OS | Jobs processed in batches, no user interaction | Older mainframe systems |
| Time-Sharing OS | Multiple users share system resources | UNIX, Linux |
| Real-Time OS | Guaranteed response time | Aircraft control, medical devices |
| Distributed OS | Multiple computers networked together | Network systems |
| Embedded OS | Specialized for specific hardware | Android, iOS, Windows Embedded |
OS Architecture
User Applications
↓
System Call Interface
↓
Kernel (Core of OS)
- Process Management
- Memory Management
- File Management
- I/O Management
↓
Hardware (CPU, Memory, Disk, I/O)Process Management
Creating, Scheduling, and Terminating Processes
Process Basics
A process is an instance of a program in execution. Each process has its own memory space and resources.
Process vs Program
| Program | Process |
|---|---|
| Static code on disk | Dynamic execution in memory |
| One program, one copy | One program, multiple processes possible |
| No resources allocated | Has CPU time, memory, I/O resources |
Process States
New → Ready → Running → Waiting → Terminated
↑_________________________↓
(Context Switch)
States:
- New: Process created
- Ready: Waiting for CPU
- Running: Currently executing
- Waiting: Waiting for I/O or event
- Terminated: Execution completeProcess Control Block (PCB)
Data structure that stores information about a process:
- PID: Process Identifier
- Program Counter: Next instruction address
- Registers: Saved register values
- Memory: Base and limit registers
- I/O Status: Open files, devices
- Priority: Scheduling priority
Context Switching
Context switching is saving one process's state and loading another's. Overhead but necessary for multitasking.
CPU Scheduling
Algorithms for Deciding Which Process Gets CPU Time
Scheduling Goals
- Maximize CPU Utilization - Keep CPU busy
- Maximize Throughput - Complete more processes
- Minimize Turnaround Time - Reduce total execution time
- Minimize Waiting Time - Reduce time in ready queue
- Minimize Response Time - Quick first response
Scheduling Algorithms
| Algorithm | Description | Pros/Cons |
|---|---|---|
| FCFS | First Come First Served | Simple but can have long waits |
| SJF | Shortest Job First | Optimal but hard to predict |
| Round Robin | Fixed time slice per process | Fair but overhead |
| Priority | Higher priority first | Starvation possible |
| Multi-level Queue | Different queues per priority | More complex |
FCFS Example
Processes: P1(24), P2(3), P3(3) (Burst time in ms) Timeline: P1: 0 -------- 24 P2: 24 -- 27 P3: 27 -- 30 Waiting Times: P1: 0, P2: 24, P3: 27 Average: 17ms
Process Synchronization
Coordinating Concurrent Processes
Critical Section Problem
When multiple processes access shared data, race conditions occur. Critical section is code accessing shared data that must execute atomically.
Solution Requirements
- Mutual Exclusion: Only one process in critical section
- Progress: Processes can't be blocked indefinitely
- Bounded Waiting: Limited waits before entering
Synchronization Tools
| Tool | Description |
|---|---|
| Semaphore | Integer with wait() and signal() operations |
| Mutex | Binary semaphore - locked or unlocked |
| Monitor | High-level construct with entry procedure |
| Lock | Simple mechanism - acquire/release |
Semaphore Example
Semaphore S = 1; // Binary semaphore Process P1: Process P2: wait(S); wait(S); // Critical Section // Critical Section signal(S); signal(S); Only ONE process enters at a time!
Deadlocks
When Processes Get Stuck Waiting for Each Other
Deadlock Definition
A deadlock is a situation where a process waits indefinitely for a resource held by another waiting process. Results in system hang.
Conditions for Deadlock (All 4 must exist)
- Mutual Exclusion: Resources can't be shared
- Hold and Wait: Processes hold resources while waiting
- No Preemption: Resources can't be forcibly taken
- Circular Wait: Circular chain of processes
Deadlock Handling Strategies
| Strategy | Approach | Cost |
|---|---|---|
| Prevention | Break one of 4 conditions | Low concurrency |
| Avoidance | Banker's algorithm - grant safely | Overhead |
| Detection | Detect deadlock, then recover | Frequent checks |
| Ignorance | Pretend deadlocks don't happen | Manual restart |
Deadlock Detection
Wait-for graph: Node = process, edge = wait relationship. Cycle = deadlock.
Memory Management
Allocating and Managing RAM
Memory Hierarchy
| Level | Speed | Size | Cost |
|---|---|---|---|
| Registers | Fastest | Bytes | Highest |
| L1 Cache | Very Fast | KB | Very High |
| L2 Cache | Fast | MB | High |
| RAM | Medium | GB | Low |
| Disk | Slow | TB | Lowest |
Memory Allocation Strategies
- Contiguous: Entire process in continuous memory
- Paging: Fixed-size pages, can be non-contiguous
- Segmentation: Variable-size segments
Paging
Divide memory into fixed-size pages (typically 4KB). Process doesn't need contiguous space.
Logical Address: Page Number | Offset Physical Address: Frame Number | Offset Example: 4KB pages Logical address 8000 → Page 1 (8000/4096) + Offset (8000%4096)
Virtual Memory
Extending Physical Memory Using Disk
Virtual Memory Concept
Virtual memory allows processes to use more memory than physically available. Unused pages stored on disk.
Demand Paging
Load pages only when needed, not all at once.
- Page Hit: Page in memory, fast access
- Page Fault: Page on disk, slow access, must load
Page Replacement Algorithms
| Algorithm | How It Works | Performance |
|---|---|---|
| FIFO | Replace oldest page first | Poor - Belady's anomaly |
| LRU | Replace least recently used | Good - approximates optimal |
| Optimal | Replace page used furthest in future | Perfect but impractical |
| Clock | Circular queue with use bit | Good - practical |
Working Set
Set of pages actively used by process. OS tries to keep working set in memory to minimize faults.
File Systems
Organizing and Managing Data on Disk
File System Basics
File system organizes data into files and directories. Manages storage space and retrieval.
File Attributes
- Name: Human-readable identifier
- Type: Extension (.txt, .exe, etc.)
- Size: Number of bytes
- Permissions: Read, write, execute
- Timestamps: Creation, modification, access time
- Owner: User who created file
File Organization
| Method | Structure | Best For |
|---|---|---|
| Contiguous | Sequential blocks | Fixed-size files |
| Linked | Blocks linked with pointers | Variable-size files |
| Indexed | Index table pointing to blocks | Random access |
Directory Structure
- Single-level: All files in one directory
- Two-level: Users have personal directories
- Tree-structured: Hierarchical directories
I/O Management
Input/Output Operations and Device Management
I/O Organization
User Program (I/O Request)
↓
I/O Manager / Device Driver
↓
I/O Controller / Hardware
↓
Physical Device (Disk, Printer, etc.)I/O Techniques
| Technique | How It Works | Speed | CPU Usage |
|---|---|---|---|
| Polling | CPU repeatedly checks device status | Slow | High (Wasteful) |
| Interrupt | Device signals CPU when ready | Fast | Low |
| DMA | Device transfers data directly to memory | Very Fast | None |
Disk Scheduling Algorithms
| Algorithm | Strategy | Seek Time |
|---|---|---|
| FCFS | Service in arrival order | Long |
| SSTF | Shortest seek time first | Short |
| SCAN | Elevator - sweep back and forth | Good |
| C-SCAN | One-way sweep, return to start | Fair |
Security & Protection
Securing System and Data
Security Goals
- Confidentiality: Keep data private
- Integrity: Prevent unauthorized changes
- Availability: System accessible when needed
User Authentication
- Password: Something you know
- Biometric: Something you are
- Physical Token: Something you have
Access Control
- DAC (Discretionary): Owner controls permissions
- MAC (Mandatory): System enforces security policy
- RBAC (Role-based): Permissions based on role
File Permissions (Unix)
rwxrwxrwx ├─ Owner (User) ├─ Group └─ Others r = read (4) w = write (2) x = execute (1) Example: 755 = rwxr-xr-x Owner: read+write+execute (7) Group: read+execute (5) Others: read+execute (5)
🎉 Congratulations!
You've completed the Operating Systems course! Master these concepts and ace your exams!
📚 Pak Notes Hub — Operating Systems Complete Notes | University Level | BS CS / BS IT
For corrections and suggestions: support@paknoteshub.com

