📚 Chapters

Operating System

Unit 1 - Introduction & Process Management

📖 Full Notes
⚡ Quick Revision
📄 PYQs
💻 Chapter 1 — Introduction to Operating System
📊 OPERATING SYSTEM - MIND MAP
OS → Software that manages hardware and provides services to applications
Structure → Monolithic, Layered, Microkernel, Modular
Functions → Process, Memory, File, I/O, Security Management
Types → Batch, Time-sharing, Real-time, Distributed, Mobile
System Calls → Interface between user programs and OS kernel
Process → Program in execution with PCB and states
1. Introduction to Operating Systems
Operating System (OS):
An Operating System is system software that acts as an intermediary between computer hardware and user applications. It manages hardware resources and provides services to application programs.
Real-life Example - Restaurant Manager:
Think of OS like a restaurant manager:
Customers (Users/Applications) want food
Kitchen (Hardware) cooks the food
Manager (OS) takes orders, assigns tasks to chefs, manages kitchen equipment, ensures everything runs smoothly

Just like manager coordinates between customers and kitchen, OS coordinates between applications and hardware!
Goals of Operating System:
1. Convenience: Make computer easy to use (GUI, commands)
2. Efficiency: Use hardware resources efficiently
3. Resource Management: Manage CPU, memory, storage, I/O devices
4. Security: Protect data and prevent unauthorized access
5. Reliability: Ensure system works correctly without failures
Components of Computer System:
4 Components: 1. Hardware (Bottom Layer) CPU, Memory, Disk, I/O devices 2. Operating System (Middle Layer) Controls hardware, provides services 3. Application Programs (Upper Layer) Word processors, browsers, games 4. Users (Top Layer) People, other computers, machines
Key Point: OS is the only program that runs at all times on the computer (called the kernel). Everything else is either a system program or application program.
2. Operating System Structure
OS Structure:
The way an operating system organizes its components and how they interact with each other.
Types of OS Structures:
1. Monolithic Structure:
All OS services run in kernel mode as a single large program.

Characteristics:
• No structure - everything in one big program
• All functions have access to all data
• Fast (no overhead of communication)

Example: MS-DOS, Early UNIX

Advantages: ✓ Fast, ✓ Simple
Disadvantages: ✗ Hard to maintain, ✗ One bug crashes entire system
2. Layered Structure:
OS divided into layers, each layer uses services of layer below it.

Layers (Bottom to Top):
Layer 0: Hardware
Layer 1: CPU Scheduling
Layer 2: Memory Management
Layer 3: I/O Management
Layer 4: User Programs

Example: THE OS, Windows NT

Advantages: ✓ Easy to debug (layer by layer), ✓ Modular
Disadvantages: ✗ Slow (many layers), ✗ Hard to define layers
3. Microkernel Structure:
Only essential services in kernel, rest run as user processes.

Kernel Contains:
• Minimal process management
• Memory management
• Inter-process communication (IPC)

User Space Contains:
• File system
• Device drivers
• Network protocols

Example: Mach, QNX, Minix

Advantages: ✓ Reliable (less code in kernel), ✓ Easy to extend
Disadvantages: ✗ Slower (frequent message passing)
4. Modular Structure (Loadable Kernel Modules):
Modern approach - kernel has core components, others loaded as modules.

How it works:
• Core kernel is small
• Modules loaded dynamically when needed
• Each module talks to core via defined interfaces

Example: Linux, Solaris

Advantages: ✓ Flexible, ✓ Efficient, ✓ Easy to add features
Best of both: Speed of monolithic + modularity of layers
3. Main Functions of Operating System
1. Process Management:
What is Process Management?
Managing programs that are currently running (processes).

OS Responsibilities:
• Create and delete processes
• Suspend and resume processes
• Provide mechanisms for process synchronization
• Provide mechanisms for process communication
• Handle deadlocks

Example: When you open Chrome, Word, and Spotify together, OS manages all three processes, decides which gets CPU time, and ensures they don't interfere with each other.
2. Memory Management:
What is Memory Management?
Managing computer's RAM (main memory).

OS Responsibilities:
• Keep track of which memory is used and by whom
• Decide which processes to load in memory
• Allocate and deallocate memory
• Prevent processes from accessing each other's memory

Example: If you have 8GB RAM and run programs needing 10GB, OS uses virtual memory (hard disk space) to manage the extra 2GB.
3. File Management:
What is File Management?
Managing files and directories on storage devices.

OS Responsibilities:
• Create and delete files and directories
• Provide operations on files (read, write, append)
• Map files to disk storage
• Backup files
• Provide file permissions and security

Example: When you save a document, OS decides where on the hard disk to store it, updates directory structure, and manages file permissions.
4. I/O Device Management:
What is I/O Management?
Managing input/output devices (keyboard, mouse, printer, etc.)

OS Responsibilities:
• Provide device drivers
• Buffer and cache data
• Handle I/O operations
• Manage device queues

Example: When you print a document, OS uses printer driver to communicate with printer, manages print queue if multiple documents are waiting.
5. Security and Protection:
What is Security?
Protecting system from unauthorized access and threats.

OS Responsibilities:
• User authentication (passwords, biometrics)
• Access control (file permissions)
• Protect processes from each other
• Defend against viruses and malware

Example: Login password, file permissions (who can read/write/execute), preventing one user from accessing another user's files.
4. Characteristics of Operating System
1. Resource Manager:
OS manages all hardware resources (CPU, memory, I/O devices) efficiently.

2. Interface Provider:
Provides user-friendly interface (GUI or Command Line) to interact with computer.

3. Multitasking:
Run multiple programs simultaneously.
Example: Listen to music while browsing and typing document.

4. Multiprogramming:
Keep multiple programs in memory and execute them by switching.

5. Time Sharing:
Multiple users can use the system simultaneously.
Example: Multiple users logged into a server.

6. Error Handling:
Detect and handle errors (hardware failure, division by zero, etc.)

7. Memory Protection:
Prevent processes from accessing memory they shouldn't.

8. Job Scheduling:
Decide which process runs when and for how long.
5. Types of Operating Systems
1. Batch Operating System:
Batch OS: Jobs grouped and executed without user interaction

Real-life Example: Bank processes all checks in one batch at night

Advantages: ✓ High throughput ✓ Less CPU idle time
Disadvantages: ✗ No interaction ✗ Long waiting
2. Time-Sharing OS (Multitasking):
Time-Sharing: Multiple users share CPU by time slicing

How: CPU gives small time to each process, switches rapidly

Examples: Windows, Linux, macOS

Advantages: ✓ Multiple users ✓ Quick response
Disadvantages: ✗ Context switching overhead
3. Real-Time OS (RTOS):
Hard Real-Time: Deadline must be met (Airbag, Pacemaker)
Soft Real-Time: Deadline can be missed occasionally (Video streaming)

Advantages: ✓ Guaranteed response ✓ High reliability
Disadvantages: ✗ Complex ✗ Expensive
4. Distributed OS:
Distributed: Multiple computers appear as one system

Example: Google servers working together

Advantages: ✓ Reliability ✓ Scalability
Disadvantages: ✗ Complex ✗ Security
5. Mobile OS:
Mobile: OS for smartphones/tablets
Examples: Android, iOS
Features: Touch interface, Battery optimization
6. System Calls
System Call: Interface between user program and OS kernel. Programs request OS services through system calls.
How System Call Works: 1. User Program → Calls library function 2. Mode Switch → User mode to Kernel mode 3. OS Kernel → Executes service 4. Return Result → Back to user program 5. Mode Switch → Kernel mode to User mode User Mode: Limited privileges, cannot access hardware Kernel Mode: Full privileges, can access everything
7. Types of System Calls
Notes Image
📊 Types of System Calls
8. System Programs
System Programs: Utilities provided with OS

Types:
1. File Management (File explorer)
2. Status Information (Task Manager)
3. File Modification (Text editors)
4. Programming Support (Compilers)
5. Program Loading (Loaders)
6. Communications (Email, FTP)
7. Background Services (Antivirus)
⚙️ Chapter 2 — Process Management
1. Process Concept
Process:
A process is a program in execution. When a program (stored on disk) is loaded into memory and executed, it becomes a process.
Program vs Process:

Program:
• Passive entity (just code stored on disk)
• Example: Chrome.exe file on hard disk
• Static (doesn't change)

Process:
• Active entity (program running in memory)
• Example: Chrome browser running on your screen
• Dynamic (state changes during execution)

Analogy:
Program = Recipe book (inactive)
Process = Cooking using recipe (active)
Components of a Process:
Notes Image
📊 Process Memory Layout
1. Text Section (Code):
• Contains executable code (instructions)
• Read-only (cannot be modified)

2. Data Section:
• Global variables
• Static variables

3. Heap:
• Dynamically allocated memory
• Grows upward during execution
• Managed by programmer (malloc/free)

4. Stack:
• Function calls
• Local variables
• Return addresses
• Grows downward during execution
2. Process Control Block (PCB)
Process Control Block (PCB):
A data structure maintained by OS for every process. Contains all information about the process. Also called Task Control Block (TCB).
Think of PCB as:
Student's report card containing all information: name, roll number, marks, attendance, behavior notes.

Similarly, PCB contains everything about a process!
Information in PCB:
Notes Image
📊 PCB Structure
1. Process ID (PID):
Unique number identifying the process
Example: Chrome PID = 1234

2. Process State:
Current state (New, Ready, Running, Waiting, Terminated)

3. Program Counter:
Address of next instruction to execute

4. CPU Registers:
Values of all CPU registers (saved during context switch)

5. CPU Scheduling Information:
• Priority
• Scheduling queue pointers

6. Memory Management Information:
• Base and limit registers
• Page tables

7. Accounting Information:
• CPU time used
• Time limits
• Process start time

8. I/O Status Information:
• List of open files
• I/O devices allocated
Why PCB is Important:
When OS switches from one process to another (context switch), it saves current process state in PCB and loads next process state from its PCB. Without PCB, OS wouldn't know where to resume execution!
3. Process States
Process States:
A process changes state during its execution. There are 5 main states a process can be in.
Notes Image
📊 Process State Diagram
1. New State:
New: Process is being created
• OS is allocating resources
• PCB is being initialized
• Not yet admitted to ready queue

Example: You double-click Chrome icon → Process in New state
2. Ready State:
Ready: Process is ready to execute, waiting for CPU
• All resources allocated except CPU
• In ready queue
• Waiting for scheduler to assign CPU

Example: Multiple students ready to ask teacher a question, waiting for their turn
3. Running State:
Running: Process is currently executing on CPU
• Instructions being executed
• Only ONE process can run on one CPU at a time

Example: Student currently asking teacher question
4. Waiting State (Blocked):
Waiting: Process waiting for some event (I/O completion)
• Cannot execute even if CPU is free
• Waiting for I/O operation to complete
• Or waiting for a signal/event

Example: Process waiting for user to click button, or waiting for file to load from disk
5. Terminated State:
Terminated: Process has finished execution
• All resources released
• PCB being deleted
• Process removed from system

Example: You close Chrome → Process terminates
4. Process State Transitions
State Transitions Explained:
1. New → Ready (Admitted):
OS admits process to ready queue
Example: OS decides there's enough memory for new process

2. Ready → Running (Scheduler Dispatch):
CPU scheduler selects process from ready queue
Example: Your process gets CPU time

3. Running → Ready (Interrupt):
Process loses CPU (time slice expired or higher priority process arrives)
Example: Timer interrupt - your time is up!

4. Running → Waiting (I/O or Event Wait):
Process needs I/O operation
Example: Process reading from disk - must wait for disk

5. Waiting → Ready (I/O Completion):
I/O operation completed, process can run again
Example: File loaded from disk, process ready to continue

6. Running → Terminated (Exit):
Process completes execution or is killed
Example: Program finishes or crashes
Real-life Example - Downloading a File:

1. New: You click download button → Process created
2. Ready: Process ready to start download
3. Running: Process starts downloading
4. Waiting: Waiting for network packets to arrive
5. Ready: Data received, ready to save to disk
6. Running: Writing data to disk
7. Terminated: Download complete!
5. Process Scheduling
Process Scheduling:
The method by which OS decides which process runs on CPU and for how long. Goal is to maximize CPU utilization and provide fair execution time to all processes.
Scheduling Queues:
Types of Queues: 1. Job Queue: All processes in the system 2. Ready Queue: Processes in main memory, ready to execute Waiting for CPU 3. Device Queue: Processes waiting for I/O device Each device has its own queue Example: Ready Queue: [P1, P3, P5] ← Waiting for CPU Disk Queue: [P2, P4] ← Waiting for disk Printer Queue: [P6] ← Waiting for printer
Types of Schedulers:
1. Long-Term Scheduler (Job Scheduler):
• Selects which processes to bring into ready queue
• Controls degree of multiprogramming
• Executes less frequently (minutes)
• Decides: New → Ready

Example: Decides whether to load new program into memory or not
2. Short-Term Scheduler (CPU Scheduler):
• Selects which process from ready queue gets CPU
• Executes very frequently (milliseconds)
• Must be very fast!
• Decides: Ready → Running

Example: Every 10ms, decides which process runs next
3. Medium-Term Scheduler:
• Swaps processes in/out of memory
• Reduces degree of multiprogramming
• Used in swapping

Example: Moves inactive process from RAM to disk to free memory
Context Switch:
Context Switch:
The process of saving state of current process and loading state of next process.
Context Switch Steps: 1. Save state of Process A in its PCB - Program counter - CPU registers - Memory maps 2. Load state of Process B from its PCB - Restore program counter - Restore CPU registers - Restore memory maps 3. Process B starts running Time: Context switch is pure overhead No useful work done during switch Typically takes 1-10 microseconds
Important: Context switching is expensive! That's why OS tries to minimize it. Too many context switches = system becomes slow.
6. Threads
Thread:
A thread is a lightweight process - the smallest unit of execution within a process. Multiple threads can exist within a single process, sharing the same resources but executing independently.
Real-life Analogy - Microsoft Word:

Single Process (Word):
• Main process = Word application

Multiple Threads within Word:
• Thread 1: Accept your typing
• Thread 2: Check spelling (red underlines)
• Thread 3: Auto-save document
• Thread 4: Display UI

All happening simultaneously within one Word process!
Process vs Thread:
Notes Image
📊 Process vs Thread
Benefits of Threads:
1. Responsiveness:
Application remains responsive even if part is blocked
Example: Web browser can download file while you browse other tabs

2. Resource Sharing:
Threads share memory and resources of process
No need for IPC mechanisms
Easier communication between threads

3. Economy:
Creating thread is cheaper than creating process
Context switch between threads is faster
Example: Thread creation 10-100x faster than process

4. Scalability (Multicore):
Threads can run on different CPU cores simultaneously
True parallelism on multicore systems
Example: Video encoding - each thread processes different frame
Types of Threads:
1. User-Level Threads (ULT):
Managed by user-level thread library, OS doesn't know about them

How it works:
• Thread library in user space manages threads
• OS sees only one process
• Thread switching done by library (no kernel involvement)

Advantages:
✓ Fast thread creation and switching
✓ Can run on any OS
✓ Flexible scheduling

Disadvantages:
✗ If one thread blocks, entire process blocks
✗ Cannot use multiple CPUs (OS thinks it's one process)

Example: Java Green Threads (old)
2. Kernel-Level Threads (KLT):
Managed directly by OS kernel

How it works:
• OS knows about each thread
• Kernel schedules threads
• OS maintains thread table

Advantages:
✓ If one thread blocks, others can continue
✓ Can use multiple CPUs (true parallelism)
✓ Better for multicore systems

Disadvantages:
✗ Slower (kernel mode switches required)
✗ More overhead

Example: Windows threads, Linux threads
Multithreading Models:
1. Many-to-One Model:
Many user threads → mapped to → One kernel thread

Diagram:
User Level: [T1] [T2] [T3] [T4]
                  ↓
Kernel Level:     [K1]

Characteristics:
• If one thread blocks, all block
• Cannot run on multiple CPUs
• Fast thread management

Example: Green Threads
2. One-to-One Model:
One user thread → mapped to → One kernel thread

Diagram:
User Level: [T1] [T2] [T3] [T4]
                  ↓    ↓    ↓    ↓
Kernel Level: [K1] [K2] [K3] [K4]

Characteristics:
• If one thread blocks, others continue
• Can use multiple CPUs
• Creating thread = creating kernel thread (overhead)
• Most systems limit number of threads

Example: Windows, Linux
3. Many-to-Many Model:
Many user threads → mapped to → Many kernel threads

Diagram:
User Level: [T1] [T2] [T3] [T4] [T5] [T6]
                  ↓    ↓    ↓
Kernel Level:     [K1] [K2] [K3]

Characteristics:
• OS creates sufficient kernel threads
• Best of both worlds
• Can run on multiple CPUs
• If one blocks, others continue

Example: Solaris, older UNIX versions
7. CPU Scheduling
CPU Scheduling:
The process of deciding which process in the ready queue gets the CPU next. Goal is to keep CPU busy and provide fair execution time to all processes.
Why Scheduling Needed?
In multiprogramming, when one process waits (for I/O), CPU switches to another process. Scheduling decides which process runs next to maximize CPU utilization.
Preemptive vs Non-Preemptive Scheduling:
Non-Preemptive Scheduling:
Once CPU is allocated to a process, process keeps it until it terminates or switches to waiting state. CPU cannot be taken away forcefully.

Characteristics:
• Process runs until completion or blocks
• No interruption by scheduler
• Simple to implement

Real-life Example:
Doctor's appointment - Once doctor starts with patient, continues until done. Next patient must wait.

Advantages:
✓ Simple
✓ Low overhead (no context switching)
✓ Predictable

Disadvantages:
✗ Long process blocks CPU for long time
✗ Poor response time
✗ Not suitable for time-sharing systems

Examples: FCFS, SJF (non-preemptive), Priority (non-preemptive)
Preemptive Scheduling:
CPU can be taken away from a running process before it completes. Scheduler can interrupt and switch to another process.

Characteristics:
• Process can be interrupted
• Higher priority process can take CPU
• Timer interrupts used

Real-life Example:
Emergency room - If critical patient arrives, doctor stops current patient and attends emergency first.

Advantages:
✓ Better response time
✓ Fair to all processes
✓ Suitable for time-sharing
✓ High priority tasks handled quickly

Disadvantages:
✗ Complex
✗ Context switch overhead
✗ Risk of race conditions

Examples: Round Robin, SRTF, Priority (preemptive)
Notes Image
📊 Preemptive vs Non-Preemptive Scheduling
8. Scheduling Criteria
Scheduling Criteria:
Metrics used to evaluate and compare different CPU scheduling algorithms. Help determine which algorithm is best for a given situation.
Key Criteria:
1. CPU Utilization:
Percentage of time CPU is busy (not idle)

Goal: Maximize (keep CPU as busy as possible)
Range: 0% to 100%
Good: 40% (lightly loaded) to 90% (heavily loaded)

Formula:
CPU Utilization = (Total Busy Time / Total Time) × 100%

Example:
If CPU is busy for 80 seconds out of 100 seconds → 80% utilization
2. Throughput:
Number of processes completed per unit time

Goal: Maximize (complete more processes)
Unit: processes/hour or processes/second

Formula:
Throughput = Number of processes completed / Total time

Example:
10 processes completed in 100 seconds → Throughput = 0.1 processes/second
3. Turnaround Time:
Total time from process submission to completion
Time interval from arrival to termination

Goal: Minimize

Formula:
Turnaround Time = Completion Time - Arrival Time
Or
Turnaround Time = Waiting Time + Burst Time

Example:
Process arrives at time 0, completes at time 10
→ Turnaround Time = 10 - 0 = 10 seconds
4. Waiting Time:
Total time process spends in ready queue waiting for CPU
Does NOT include execution time

Goal: Minimize

Formula:
Waiting Time = Turnaround Time - Burst Time

Example:
Turnaround Time = 10s, Burst Time = 3s
→ Waiting Time = 10 - 3 = 7 seconds
5. Response Time:
Time from process submission to first response (first time it gets CPU)
Important for interactive systems

Goal: Minimize

Formula:
Response Time = Time of first response - Arrival Time

Example:
Process arrives at 0, first gets CPU at time 5
→ Response Time = 5 - 0 = 5 seconds

Difference from Waiting Time:
Response time is till FIRST response, waiting time is TOTAL waiting
Notes Image
📊 Summary of Scheduling Criteria
Important:
No single algorithm is best for all criteria. Trade-offs exist:
• Algorithm good for throughput may have poor response time
• Algorithm minimizing waiting time may reduce CPU utilization
• Choice depends on system requirements (batch vs interactive)
9. CPU Scheduling Algorithms
Scheduling Algorithms:
Rules/methods used by CPU scheduler to decide which process from the ready queue gets the CPU next.
1. First Come First Serve (FCFS):
FCFS: Simplest algorithm. Process that arrives first gets CPU first. Non-preemptive.
Real-life Example: Queue at ticket counter - First person in line gets served first!

Implementation: Using FIFO queue
• New process added to tail of queue
• Scheduler picks from head of queue
Notes Image
📊 Example of FCFS Scheduling
Advantages:
✓ Simple and easy to implement
✓ Fair (first come, first served)
✓ No starvation
Disadvantages:
✗ Convoy Effect (short processes wait for long process)
✗ Poor average waiting time
✗ Not suitable for time-sharing systems
✗ Non-preemptive (cannot interrupt)
Convoy Effect: When short processes wait for a long process to complete. Like being stuck behind a slow truck on highway - all fast cars must wait!
2. Shortest Job First (SJF):
SJF: Process with smallest burst time gets CPU first. Can be preemptive or non-preemptive. Optimal algorithm (gives minimum average waiting time).
Notes Image
📊 Example of Non-Preemptive SJF Scheduling
Advantages:
✓ Minimum average waiting time
✓ Optimal algorithm
✓ Better throughput than FCFS
Disadvantages:
✗ Starvation (long processes may never execute)
✗ Cannot know exact burst time in advance
✗ Requires prediction of burst time
3. Shortest Remaining Time First (SRTF):
SRTF: Preemptive version of SJF. If new process arrives with shorter remaining time than current process, CPU switches to new process.
Notes Image
📊 Example of Preemptive SJF (SRTF) Scheduling
4. Priority Scheduling:
Priority Scheduling: Each process has a priority. CPU allocated to process with highest priority. Can be preemptive or non-preemptive.
Priority Values:
• Lower number = Higher priority (usually)
• Example: Priority 1 > Priority 5

Real-life Example: Emergency room - Critical patients (high priority) treated before minor injuries (low priority)
Notes Image
📊 Example of Non-Preemptive Priority Scheduling
Major Problem - Starvation:
Low priority processes may never execute if high priority processes keep arriving.

Solution - Aging:
Gradually increase priority of waiting processes over time.
Example: Every 10 minutes waiting → increase priority by 1
5. Round Robin (RR):
Round Robin: Each process gets small unit of CPU time (time quantum), then moved to end of queue. Preemptive. Designed for time-sharing systems.
Real-life Example: Teacher giving each student 5 minutes to ask questions. After 5 minutes, next student gets turn. First student goes to back of line if more questions.

Time Quantum (q): Fixed time slice (typically 10-100 milliseconds)
Notes Image
📊 Example of Round Robin Scheduling
Advantages:
✓ Fair to all processes
✓ No starvation
✓ Good response time
✓ Suitable for time-sharing systems
Disadvantages:
✗ Context switch overhead
✗ Performance depends on time quantum
✗ Average waiting time often high
Choosing Time Quantum:
Too large: Becomes like FCFS (poor response)
Too small: Too many context switches (overhead)
Rule of thumb: 80% of processes should complete within one quantum
6. Multilevel Queue Scheduling:
Multilevel Queue: Ready queue divided into multiple queues based on process characteristics. Each queue has its own scheduling algorithm.
Notes Image
📊 Multilevel Queue Scheduling
Example Categories:
Foreground (Interactive): User applications (high priority, RR)
Background (Batch): Compilations, backups (low priority, FCFS)
Advantages:
✓ Different algorithms for different process types
✓ Low overhead (no queue switching)
✓ Priority-based execution
Disadvantages:
✗ Starvation (low priority queues may starve)
✗ Inflexible (process cannot move between queues)
10. Scheduling Algorithms Comparison
Notes Image
📊 Complete Comparison of Scheduling Algorithms
Key Takeaways:
FCFS: Simplest but convoy effect
SJF: Optimal but starvation possible
SRTF: Better than SJF but more overhead
Priority: Flexible but needs aging for starvation
Round Robin: Fair but context switch overhead
Multilevel: Realistic but complex

No algorithm is perfect! Choice depends on system requirements.
11. Inter-process Communication (IPC)
Inter-process Communication (IPC):
Mechanism that allows processes to communicate and synchronize their actions. Processes need to exchange data and coordinate execution.
Why IPC Needed?
• Share information between processes
• Speed up computation (divide work among processes)
• Modularity (separate concerns)
• Convenience (user may run multiple tasks)

Example: Web browser - one process downloads, another displays, another handles user input
Two Models of IPC:
1. Shared Memory:
Processes share a common memory region for communication

How it works:
• OS creates shared memory segment
• Processes read/write to this shared region
• Fast (no kernel involvement after setup)

Advantages:
✓ Fast (direct memory access)
✓ Efficient for large data transfer

Disadvantages:
✗ Need synchronization (to avoid conflicts)
✗ Complex to implement
2. Message Passing:
Processes communicate by sending/receiving messages

Operations:
• send(message)
• receive(message)

Advantages:
✓ Easier to implement
✓ Works for distributed systems
✓ No conflicts (OS manages)

Disadvantages:
✗ Slower (kernel calls needed)
✗ Overhead for small messages
Notes Image
📊 Comparison
12. Remote Procedure Calls (RPC)
Remote Procedure Call (RPC):
Allows a program to execute a procedure (function) on another machine as if it were a local call. Makes distributed computing transparent.
Real-life Analogy:
Ordering food by phone:
• You call restaurant (remote machine)
• Ask for pizza (call procedure)
• Wait for delivery (wait for result)
• Get pizza (receive result)

You don't go to restaurant yourself - phone call handles everything!
Notes Image
📊 How RPC Works
Key Point: Client doesn't know the function is executing remotely. RPC makes remote calls look like local calls!
13. Process Synchronization
Process Synchronization:
Coordination of execution of multiple processes to ensure data consistency when processes access shared resources.
Why Synchronization Needed?

Example - Bank Account (Race Condition):
Initial Balance = ₹1000

Process A: Withdraw ₹500
1. Read balance (₹1000)
2. Calculate: 1000 - 500 = ₹500
3. Write back ₹500

Process B: Deposit ₹300 (runs simultaneously)
1. Read balance (₹1000) ← Wrong! Should be ₹500
2. Calculate: 1000 + 300 = ₹1300
3. Write back ₹1300

Final Balance: ₹1300 (Wrong! Should be ₹800)
₹500 deposit lost! This is a race condition.
Critical Section Problem:
Critical Section: Part of code where shared resources are accessed. Only one process should execute in critical section at a time.
Critical Section Structure: do { // Entry Section (request permission) // CRITICAL SECTION // (access shared resource) // Exit Section (release permission) // Remainder Section // (other code) } while (true);
Requirements for Solution:
1. Mutual Exclusion:
Only one process in critical section at a time

2. Progress:
If no process in critical section, selection of next process cannot be postponed indefinitely

3. Bounded Waiting:
Limit on number of times other processes can enter CS before a waiting process gets turn (no starvation)
Synchronization Mechanisms:
• Semaphores
• Monitors
• Mutex locks
(Covered in detail in Unit 2)
Quick Revision — Last Minute Exam Prep!
📌 How to use: Read this 15 minutes before exam. Focus on definitions, formulas, diagrams, and comparison points. For numericals, always draw the Gantt chart first.

💻 Chapter 1 — OS Basics & Structure

📖 Operating System:
An OS is system software that works as an interface between user/application programs and hardware.

Memory Trick: OS = Manager + Interface + Service Provider
Example: When Chrome saves a file, OS handles disk access, memory, CPU time, and permissions.
✅ Main OS Goals (Remember "CERS"):
Convenience — Makes computer easy to use
Efficiency — Uses hardware properly
Resource Management — CPU, memory, files, I/O devices
Security — Protects data and controls access

Exam Line: OS hides hardware complexity and provides a clean environment for programs.
🏗️ OS Structure Quick Comparison:
Structure Key Idea Exam Point
Monolithic All services inside kernel Fast but difficult to maintain; one bug can affect whole system
Layered OS divided into layers Easy debugging, but layer overhead exists
Microkernel Only minimum services in kernel Reliable and secure, but message-passing overhead
Modular Loadable kernel modules Flexible; modern OS style
Must Draw:
User → Application Programs → System Calls → Kernel → Hardware

Write below diagram: System calls are the controlled entry point from user mode to kernel mode.

🔄 Chapter 2 — OS Types & System Calls

🧠 Types of OS — One-Line Revision:
Type Meaning Example / Use
Batch OS Jobs collected and executed in batches Old payroll/billing systems
Time-Sharing OS CPU time divided among users/processes Multi-user systems
Real-Time OS Responds within strict deadline Medical, aviation, robotics
Distributed OS Multiple machines appear as one system Cluster/cloud style systems
Mobile OS Optimized for touch, battery, sensors Android, iOS
📞 System Call:
A system call is the interface through which a user program requests services from the OS kernel.

Flow: User Program → System Call → Kernel Mode → Hardware Service → Return Result
🔑 5 Types of System Calls (Remember "P-F-D-I-C"):
Process Control — fork(), exit(), wait()
File Management — open(), read(), write()
Device Management — ioctl(), read device, write device
Information Maintenance — getpid(), time()
Communication — send(), receive(), pipe()
⚠️ Common Confusion:
User mode has limited access. Kernel mode has full hardware access. System calls safely switch from user mode to kernel mode.

⚙️ Chapter 3 — Process, PCB & Threads

📖 Process: A program in execution.
Program: Passive code stored on disk.

Quick Example: Chrome installer file = Program. Running Chrome window = Process.
🔁 Process States:
State Meaning Transition Hint
New Process is being created Admitted to ready queue
Ready Waiting for CPU Scheduler dispatches it
Running Currently using CPU Can finish, wait, or be preempted
Waiting Waiting for I/O/event Event completion sends it to ready
Terminated Execution finished Resources released
PCB Contains (Remember "S-P-R-M-O"):
State, Program Counter, Registers, Memory info, Open files / I-O status

Context Switch: Save current PCB + Load next PCB
Exam Line: Context switching is pure overhead because CPU is not doing user work during switch.
✅ Threads:
Thread is a lightweight process. Threads of same process share code, data, and files but have separate PC, registers, and stack.

Benefits: Responsiveness, resource sharing, economy, scalability
Models: Many-to-One, One-to-One, Many-to-Many

📊 Chapter 4 — CPU Scheduling

📐 Scheduling Formulas:
Turnaround Time (TAT) = Completion Time - Arrival Time
Waiting Time (WT) = Turnaround Time - Burst Time
Response Time (RT) = First Response Time - Arrival Time

Average: Add all values / Number of processes
⏱️ Scheduling Algorithms Quick Table:
Algorithm Type Key Point
FCFS Non-preemptive Simple, but convoy effect
SJF Non-preemptive Minimum average waiting time, but starvation possible
SRTF Preemptive Preemptive SJF; check at every arrival
Priority Both possible Starvation solved by aging
Round Robin Preemptive Fair; depends on time quantum
Multilevel Queue Queue based Different queues can use different algorithms
❌ Scheduling Mistakes to Avoid:
1. Forgetting arrival time while drawing Gantt chart
2. Confusing TAT and WT formulas
3. In SRTF, not checking every new arrival
4. In Round Robin, forgetting time quantum and context order
5. Not writing average waiting/turnaround time at the end
💡 Numerical Answer Format:
1. Write given table
2. Draw Gantt chart
3. Find Completion Time for each process
4. Apply TAT = CT - AT
5. Apply WT = TAT - BT
6. Calculate averages

💬 Chapter 5 — IPC & Synchronization

📖 IPC: Inter-Process Communication allows processes to exchange data and coordinate work.

Two Models:
Shared Memory: Fast, but synchronization required
Message Passing: Easier and safer, but slower due to copying/OS involvement
🔐 Critical Section Requirements:
1. Mutual Exclusion: Only one process enters critical section at a time
2. Progress: If CS is empty, decision of next process cannot be delayed forever
3. Bounded Waiting: A waiting process must get chance after a limited number of turns
✅ Synchronization Tools:
Semaphore, mutex lock, monitor, message passing.

Exam Line: Synchronization prevents race condition when multiple processes access shared data.
⚠️ Race Condition vs Deadlock vs Starvation:
Race Condition: Output depends on timing/order of execution
Deadlock: Processes wait for each other permanently
Starvation: Process waits indefinitely because others keep getting priority

🎯 Last Minute Exam Strategy

❌ Top Mistakes Students Make:
1. Writing OS definition without mentioning hardware/resource management
2. Mixing up program, process, and thread
3. Forgetting PCB contents in process questions
4. Drawing Gantt chart without arrival time check
5. Explaining race condition without shared data example
✅ 2 Mark Questions Strategy:
• Definition + one example = complete answer
• For "list" questions, write exact points in bullets
• For difference questions, make a small two-column table
• Keep answer short: 4-5 lines maximum
✅ 5 Mark Questions Strategy:
• Definition + diagram/table + explanation + example
• OS structure: draw User → System Call → Kernel → Hardware
• Process states: draw state transition diagram
• Scheduling: Gantt chart is compulsory for numericals
• IPC/Synchronization: use shared variable example for clarity

Time Management: 2M = 3 minutes, 5M = 8 minutes
🔥 Must Revise Before Closing:
  • OS definition, goals, and functions
  • Monolithic vs Layered vs Microkernel vs Modular structure
  • System call flow and 5 system call types
  • Process states diagram and PCB contents
  • Thread benefits and thread models
  • Scheduling formulas: TAT, WT, RT
  • FCFS, SJF, SRTF, Priority, Round Robin comparison
  • IPC models and critical section requirements
✅ Final 10-Minute Plan:
1. Revise formulas first
2. Redraw process state diagram once
3. Revise scheduling algorithm table
4. Read OS structure comparison
5. Enter exam with one clear example for every theory answer
📄 Previous Year Questions

Previous Year Question Paper Not Available Yet

Previous year question papers for this unit are not available yet. If you have the question paper, please share it through the contact page so it can be added for other students.