https://drive.google.com/drive/folders/1VAYZuJLVeDBUd1UM2C4nvJTysqB3fMmt
📌 Module 1: Operating System Fundamentals
1️⃣ Introduction to Operating System & Evolution
What is an Operating System (OS)?
An Operating System (OS) is system software that acts as an interface between hardware and users, managing system resources efficiently.
Key Functions of an OS
✅ Process Management – Controls execution of programs
✅ Memory Management – Allocates memory to processes
✅ File System Management – Manages files and directories
✅ Device Management – Controls hardware devices
✅ Security & Access Control – Protects data and system resources
2️⃣ Evolution of Operating Systems
| Era | OS Type | Example | Characteristics |
|---|---|---|---|
| 1950s | Batch OS | IBM Mainframes | Executes jobs sequentially |
| 1960s | Multiprogramming OS | UNIX | Runs multiple processes simultaneously |
| 1970s | Time-Sharing OS | MULTICS | CPU switches between multiple users |
| 1980s | Personal Computing OS | MS-DOS, Mac OS | Single-user OS for PCs |
| 1990s | GUI-Based OS | Windows 95, Linux | User-friendly interfaces |
| 2000s+ | Mobile & Cloud OS | Android, iOS | Internet-based, mobile computing |
3️⃣ Types of Operating Systems
1. Batch OS
📌 Definition: Executes jobs in batches without user interaction.
📌 Example: Early IBM Mainframes
📌 Use Cases: Payroll processing, Banking
2. Time-Sharing OS
📌 Definition: Allows multiple users to use the system simultaneously.
📌 Example: UNIX, Windows Multi-User Mode
📌 Use Cases: Cloud computing, Online databases
3. Distributed OS
📌 Definition: Manages multiple connected computers as one system.
📌 Example: Google Cloud, Hadoop
📌 Use Cases: Cloud services, Large-scale computing
4. Real-Time OS (RTOS)
📌 Definition: Executes tasks within strict time constraints.
📌 Example: FreeRTOS, VxWorks
📌 Use Cases: Self-driving cars, Medical devices, Robotics
📌 System Calls in Linux (Using Python)
1️⃣ What are System Calls?
A System Call is a request made by a user-space program to the operating system kernel to perform low-level operations like process control, file handling, and inter-process communication.
📌 Why are System Calls Important?
- They provide a controlled interface between user programs and hardware resources.
- They ensure security by restricting direct hardware access.
- They allow multitasking, file management, and memory management.
2️⃣ File Handling System Calls in Python (open(), read(), write(), close())
📝 Explanation:
File system calls allow reading, writing, and modifying files at the OS level. In Python, we use built-in functions that internally call Linux system functions.
Python Program (Run in PuTTY)
✅ Use Case: Logging, configuration files, storing data
📌 Run this in PuTTY:
3️⃣ Process Management System Calls (fork(), exec(), wait())
📝 Explanation:
fork(): Creates a child process by duplicating the parent process.exec(): Replaces the current process with a new program.wait(): Makes the parent wait until the child process completes execution.
Python Program for fork() (Run in PuTTY)
✅ Use Case: Used in multitasking, web servers, process scheduling
📌 Run this in PuTTY:
4️⃣ Executing a New Program Using exec()
📝 Explanation:
- The
exec()system call replaces the current process with a new program. - It is often used to run shell commands from Python.
Python Program for exec()
✅ Use Case: Running shell commands, executing scripts dynamically
📌 Run this in PuTTY:
✅ Expected Output: Lists all files in the current directory.
5️⃣ Process Synchronization Using wait()
📝 Explanation:
wait()makes the parent process wait until the child process finishes.- Used for process synchronization.
Python Program for wait()
✅ Use Case: Used in multi-processing and synchronization
📌 Run this in PuTTY:
📌 OS Architecture
1️⃣ What is OS Architecture?
An OS architecture defines how the operating system is structured internally.
| Type | Definition | Example OS |
|---|---|---|
| Monolithic Kernel | All services run inside the kernel | Linux, UNIX |
| Microkernel | Only essential services run in the kernel | Minix, QNX |
| Hybrid Kernel | Mix of Monolithic & Microkernel | Windows, macOS |
📌 Module 2: Process Management (with Python Examples on Linux via PuTTY)
In this module, we'll cover:
✅ Process Lifecycle (Creation, Scheduling, Termination)
✅ Process Control Block (PCB)
✅ Context Switching & Scheduling Algorithms
Each topic includes explanations and Python programs for real-time execution in Linux via PuTTY.
1️⃣ Process Lifecycle
Every process in an OS goes through different states during execution.
📌 Process States
| State | Description |
|---|---|
| New | Process is created but not yet running. |
| Ready | Process is waiting to be assigned a CPU. |
| Running | Process is executing on the CPU. |
| Waiting | Process is waiting for I/O or another resource. |
| Terminated | Process has completed execution. |
📌 Process Lifecycle Diagram
📝 Python Example: Process Creation & Termination
Let's simulate process creation and termination using fork() in Python.
✅ Run this in PuTTY:
✅ Expected Output:
📌 Explanation:
fork()creates a new child process.wait()ensures the parent waits until the child completes execution.
2️⃣ Process Control Block (PCB)
Each process in an OS is represented by a Process Control Block (PCB).
The PCB stores all important information about a process.
📌 PCB Contains
| Field | Description |
|---|---|
| PID | Process ID |
| Process State | New, Ready, Running, etc. |
| Program Counter | Stores the address of the next instruction |
| CPU Registers | Stores CPU execution data |
| Memory Info | Page tables, stack, heap information |
| I/O Info | File descriptors, open files, etc. |
📝 Python Example: Simulating a PCB
✅ Run this in PuTTY:
✅ Expected Output:
📌 Explanation:
os.getpid(): Gets the current process ID.os.getppid(): Gets the parent process ID.os.getuid(): Gets the user ID running the process.os.getgid(): Gets the group ID.
3️⃣ Context Switching & Scheduling Algorithms
Context Switching happens when the OS switches the CPU from one process to another.
📌 Why Context Switching?
- Allows multitasking by switching between processes.
- Saves the current process state and restores another process state.
- Uses a scheduler to decide which process runs next.
📌 Scheduling Algorithms
| Algorithm | Description |
|---|---|
| FCFS (First Come First Serve) | Executes processes in the order they arrive. |
| SJF (Shortest Job First) | Executes the shortest process first. |
| Round Robin (RR) | Allocates a time slice to each process. |
| Priority Scheduling | Executes the process with the highest priority. |
📝 Python Program: Simulating FCFS Scheduling
✅ Run this in PuTTY:
✅ Expected Output:
📌 Explanation:
- Processes are executed in order of arrival.
- Simulates process execution times using
time.sleep().
📝 Python Program: Simulating Round Robin Scheduling
✅ Run this in PuTTY:
✅ Expected Output:
📌 Explanation:
- Each process gets 2 seconds (time quantum).
- If process is incomplete, it re-enters the queue.
📌 Process Scheduling Algorithms (With Python Implementation in Linux via PuTTY)
Now, we'll cover:
✅ First-Come-First-Serve (FCFS) Scheduling
✅ Shortest Job Next (SJN) Scheduling
✅ Round Robin (RR) Scheduling
✅ Multi-Level Queue Scheduling
Each scheduling algorithm includes:
📌 Concept Explanation
📌 Python Program (Run in PuTTY)
📌 Step-by-Step Execution
1️⃣ First-Come-First-Serve (FCFS) Scheduling
📝 Explanation:
- Non-Preemptive: Once a process starts, it runs till completion.
- Processes are executed in the order they arrive.
- Waiting Time can be high if the first process is long.
📌 Python Program for FCFS Scheduling
✅ Run in PuTTY:
✅ Expected Output:
📌 Real-Time Example:
Imagine customers in a queue at a bank; whoever arrives first gets served first.
2️⃣ Shortest Job Next (SJN) Scheduling
📝 Explanation:
- Non-Preemptive: The shortest process is executed first.
- Reduces waiting time but requires knowing burst times in advance.
- May cause starvation (longer processes may be delayed).
📌 Python Program for SJN Scheduling
✅ Run in PuTTY:
✅ Expected Output:
📌 Real-Time Example:
In a hospital emergency room, patients with minor injuries (short burst time) are treated before those needing long surgeries.
3️⃣ Round Robin (RR) Scheduling
📝 Explanation:
- Preemptive: Each process gets a time quantum (small execution time).
- If a process doesn’t finish in its quantum, it moves to the end of the queue.
- Fair for all processes, used in time-sharing systems.
📌 Python Program for Round Robin Scheduling
✅ Run in PuTTY:
✅ Expected Output:
📌 Real-Time Example:
Imagine a time-sharing system where multiple users get a fixed CPU time slice to run their programs.
4️⃣ Multi-Level Queue Scheduling
📝 Explanation:
- Divides processes into different priority queues.
- Each queue has its own scheduling algorithm (FCFS, SJN, RR, etc.).
- Used in real-time systems to handle different process types efficiently.
📌 Python Program for Multi-Level Queue Scheduling
✅ Run in PuTTY:
✅ Expected Output:
📌 Real-Time Example:
- System Processes (High Priority) → Kernel tasks.
- Interactive Processes (Medium Priority) → User applications.
- Background Processes (Low Priority) → File downloads, backup tasks.
📌 Threading & Concurrency in Linux (User vs. Kernel Threads)
Now, we'll cover:
✅ What are Threads?
✅ Difference Between User Threads & Kernel Threads
✅ Python Programs for Threading & Concurrency (FCFS & Round Robin Scheduling)
📝 What are Threads?
- A thread is the smallest unit of execution in a process.
- A process can have multiple threads, each performing different tasks concurrently.
- Threads share the same memory space but have independent execution.
🔍 User Threads vs. Kernel Threads
| Feature | User Threads | Kernel Threads |
|---|---|---|
| Managed By | User-level libraries (e.g., pthread in Python) | OS Kernel |
| Context Switching | Faster (No kernel involvement) | Slower (Requires kernel mode switch) |
| Performance | High, as no system call needed | Lower due to system calls |
| Blocking | One thread blocking can block the whole process | Independent execution |
| Examples | Python threading, Java Threads | Kernel-level scheduling |
📌 Real-Time Example:
- User Threads: Lightweight applications like web scraping, chat applications.
- Kernel Threads: System-level tasks like process scheduling, drivers.
🛠 Practical: FCFS Scheduling Using Threads (Python in Linux via PuTTY)
We will implement First-Come-First-Serve (FCFS) Scheduling using Python threads.
📌 Python Program for FCFS Scheduling Using Threads
✅ Run in PuTTY:
✅ Expected Output:
📌 Real-Time Example:
This is like a queue system in a bank where each customer is served in order of arrival.
🛠 Practical: Round Robin Scheduling Using Threads (Python in Linux via PuTTY)
We will now implement Round Robin Scheduling using threads.
📌 Python Program for Round Robin Scheduling Using Threads
✅ Run in PuTTY:
✅ Expected Output:
📌 Real-Time Example:
This is like a CPU time-sharing system where each process gets a fixed time slice before the next process executes.
📌 Module 3: Synchronization & Deadlocks
✅ Race Conditions & Critical Sections
In this module, we'll cover:
✅ What is a Race Condition?
✅ What is a Critical Section?
✅ Solving Race Conditions using Mutex Locks (Python in Linux via PuTTY)
📝 What is a Race Condition?
A race condition occurs when multiple threads or processes try to access and modify shared resources at the same time, leading to inconsistent data or unexpected behavior.
📌 Example:
Imagine two people withdrawing money from the same bank account at the same time. If they both check the balance at the same time and withdraw, they might end up withdrawing more than what’s available.
📝 What is a Critical Section?
A critical section is a part of a program where a shared resource is accessed. If multiple threads enter the critical section at the same time, data inconsistency occurs.
📌 Example:
- Shared Printer: Two users sending print jobs at the same time may cause garbled output.
- Shared Bank Account: Two people withdrawing at the same time may result in an incorrect balance.
🔴 Problem: If multiple threads access the critical section without control, race conditions occur.
✅ Solution: Use Mutex Locks (Mutual Exclusion Locks) to prevent multiple threads from accessing the critical section simultaneously.
🛠 Solving Race Condition using Mutex Locks (Python in Linux via PuTTY)
We will use threading with a mutex lock to prevent a race condition when multiple threads modify a shared variable.
📌 Python Program: Without Mutex (Race Condition)
✅ Run in PuTTY:
✅ Expected Output (Inconsistent Result due to Race Condition):
📌 Issue: Both threads read the same initial balance before updating it, causing an incorrect final balance.
📌 Python Program: Fixing Race Condition with Mutex Lock
✅ Run in PuTTY:
✅ Expected Output (Correct Result using Mutex Lock):
📌 How Mutex Fixes It?
- The first thread acquires the lock, modifies the balance, and releases the lock.
- The second thread waits until the first thread finishes, preventing data corruption.
📌 Synchronization Mechanisms in Operating Systems
✅ Mutex Locks
✅ Semaphores
✅ Monitors
We will cover real-time explanations with Python programs for Linux (PuTTY).
📝 1. Mutex Locks (Mutual Exclusion Locks)
A Mutex (Mutual Exclusion Lock) allows only one thread/process to access a shared resource at a time.
When a thread locks a mutex, other threads must wait until it is unlocked.
🔍 Real-World Example
📌 ATM Machine: Only one person can use an ATM at a time. Others must wait until the ATM is free.
🛠 Python Program: Using Mutex Lock for Synchronization
✅ Run in PuTTY:
✅ Expected Output:
📌 Key Takeaway: The mutex lock ensures only one thread modifies the balance at a time.
📝 2. Semaphores
A Semaphore is a synchronization mechanism that controls access to a shared resource using a counter.
- Binary Semaphore (0 or 1): Works like a mutex (only one process can access).
- Counting Semaphore (>1): Allows multiple processes to access resources up to a limit.
🔍 Real-World Example
📌 Restaurant Tables: If a restaurant has 5 tables, only 5 customers can sit at a time. Others must wait.
🛠 Python Program: Using Semaphores for Synchronization
✅ Run in PuTTY:
✅ Expected Output:
📌 Key Takeaway: Only 2 threads can access the resource at the same time.
📝 3. Monitors
A Monitor is a synchronization construct that allows only one process/thread to access a shared resource at a time with automatic locking and unlocking.
📌 How Monitors Work?
- Encapsulates shared data + synchronization methods.
- Only one thread executes inside the monitor at a time.
- Automatically handles locks (unlike mutex/semaphores).
🔍 Real-World Example
📌 Java synchronized block: In Java, synchronized methods act like monitors, automatically locking and unlocking resources.
🛠 Python Program: Monitor Implementation using threading.Condition
✅ Run in PuTTY:
✅ Expected Output:
📌 Key Takeaway:
- The consumer waits until the producer notifies it that the resource is available.
threading.Condition()ensures safe synchronization between producer and consumer.
📌 Deadlocks in Operating Systems
✅ Conditions for Deadlock (Coffman’s Conditions)
✅ Deadlock Detection, Avoidance, and Prevention
✅ Banker’s Algorithm
🛠 Practical: Solve the Dining Philosophers Problem using Semaphores in Python
📝 1. What is a Deadlock?
A deadlock occurs when a group of processes wait indefinitely for resources held by each other, causing the system to halt.
🔍 Real-World Example of Deadlock
📌 Traffic Deadlock:
- Four cars arrive at an intersection, each waiting for the other to move.
- No one moves because everyone is waiting for a resource (road space).
- The system is stuck in deadlock.
📝 2. Conditions for Deadlock (Coffman’s Conditions)
A deadlock occurs if these four conditions hold simultaneously:
| Condition | Description |
|---|---|
| Mutual Exclusion | A resource can only be used by one process at a time. |
| Hold and Wait | A process is holding a resource while waiting for another. |
| No Preemption | A resource cannot be forcibly taken from a process. |
| Circular Wait | A cycle of processes exists where each is waiting for a resource held by the next. |
📌 Example:
- P1 has R1 and needs R2.
- P2 has R2 and needs R1.
- Both processes wait forever, causing a deadlock.
📝 3. Deadlock Handling Strategies
| Strategy | Description |
|---|---|
| Deadlock Prevention | Prevent at least one Coffman condition from occurring. |
| Deadlock Avoidance | Use an algorithm (like Banker’s Algorithm) to avoid unsafe resource allocation. |
| Deadlock Detection & Recovery | Detect deadlocks and recover using process termination or resource preemption. |
📝 4. Banker's Algorithm (Deadlock Avoidance)
The Banker’s Algorithm ensures a system never enters an unsafe state, preventing deadlocks.
🔍 Real-World Example
📌 Bank Loan System:
- A bank does not approve a loan if it cannot ensure enough resources to fulfill all commitments.
- Similarly, the Banker's Algorithm ensures that resource allocation never leads to a deadlock.
🛠 Python Program: Implementing Banker's Algorithm
✅ Run in PuTTY:
✅ Expected Output:
📌 Key Takeaway:
- The system is safe if it can allocate resources without causing a deadlock.
- If there is no safe sequence, the system may enter a deadlock state.
🛠 Practical: Solve the Dining Philosophers Problem using Semaphores
The Dining Philosophers Problem is a classic synchronization problem involving deadlocks and starvation.
🔍 Problem Explanation
- Five philosophers sit around a table with a fork between each pair.
- Each philosopher must pick up two forks to eat.
- If all philosophers pick up one fork at the same time, a deadlock occurs.
🛠 Python Program: Solve Dining Philosophers Problem using Semaphores
✅ Run in PuTTY:
✅ Expected Output (Runs continuously):
📌 Key Takeaway:
- Semaphores prevent deadlocks by allowing only one philosopher to use a fork at a time.
- The dining philosophers problem is an excellent example of resource allocation & deadlock prevention.
Module 4: Memory Management step by step.
📌 Memory Management in Operating Systems
✅ 1. Contiguous Memory Allocation (Fixed & Dynamic Partitioning)
✅ 2. Paging & Segmentation
🛠 Practical: Python Programs for Memory Management
🔍 1. Contiguous Memory Allocation
In contiguous memory allocation, processes are stored in a single continuous block of memory.
🔹 Types of Contiguous Memory Allocation
1️⃣ Fixed Partitioning (Static Allocation)
- Memory is divided into fixed-size partitions before execution.
- Wastes memory if a process is smaller than the partition (Internal Fragmentation).
2️⃣ Dynamic Partitioning
- Partitions are created dynamically when a process arrives.
- Avoids internal fragmentation, but may cause external fragmentation.
🛠 Python Program: Simulating Fixed & Dynamic Partitioning
✅ Run in PuTTY:
📌 Key Takeaways:
- Fixed Partitioning wastes memory if partition is too large (internal fragmentation).
- Dynamic Partitioning utilizes memory better but may cause external fragmentation.
🔍 2. Paging (Non-Contiguous Allocation)
Paging divides process memory into fixed-size pages and RAM into fixed-size frames to eliminate external fragmentation.
🔹 How Paging Works?
1️⃣ Process is divided into pages (4KB, 8KB, etc.)
2️⃣ RAM is divided into frames of the same size
3️⃣ Pages are loaded into available frames
4️⃣ A Page Table keeps track of frame locations
✅ Real-Life Example:
- A book (process) is divided into chapters (pages).
- A shelf (RAM) is divided into sections (frames).
- Chapters are stored in different sections, but a table of contents (Page Table) helps in locating them.
🛠 Python Program: Simulating Paging
✅ Run in PuTTY:
✅ Expected Output:
📌 Key Takeaways:
- No external fragmentation since memory is divided into equal-sized frames.
- Page Table helps in mapping logical addresses to physical addresses.
🔍 3. Segmentation (Logical Division of Memory)
Segmentation divides a process into variable-sized segments, based on logical divisions (code, stack, heap, etc.).
✅ Real-Life Example:
- A C program has Code, Data, Stack, Heap segments.
- Instead of equal-sized pages, segments are different in size based on their role.
🛠 Python Program: Simulating Segmentation
✅ Run in PuTTY:
✅ Expected Output:
📌 Key Takeaways:
- Segmentation follows logical memory division.
- Variable-sized segments eliminate internal fragmentation but may cause external fragmentation.
📌 Virtual Memory in Operating Systems
Virtual Memory is a memory management technique that allows the execution of processes that may not be completely in memory.
✅ 1. Demand Paging
✅ 2. Page Replacement Algorithms (FIFO, LRU, Optimal)
🛠 Practical: Implement Page Replacement Algorithms in Python
🔍 1. Demand Paging
Demand Paging is a virtual memory mechanism where pages are loaded into memory only when required.
✅ How it works?
1️⃣ When a process is executed, only necessary pages are loaded into RAM.
2️⃣ If a required page is not in memory, a page fault occurs.
3️⃣ The OS loads the missing page from disk (swap space).
✅ Advantage: Saves memory by loading only required pages.
✅ Disadvantage: Causes page faults, which slow down performance.
📌 Example:
Imagine a video game where only visible levels are loaded into memory. As the player moves, new levels are loaded on demand.
🔍 2. Page Replacement Algorithms
When RAM is full, the OS must replace a page to load a new one. Different algorithms decide which page to remove.
🔹 FIFO (First-In-First-Out) Algorithm
- The oldest page in memory is replaced first.
- Simple but inefficient (removes frequently used pages).
🛠 Python Program for FIFO Page Replacement
✅ Run in PuTTY:
📌 Key Takeaway: FIFO is simple but may replace frequently used pages, causing more faults.
🔹 LRU (Least Recently Used) Algorithm
- Replaces the least recently used page.
- More efficient than FIFO but requires tracking usage history.
🛠 Python Program for LRU Page Replacement
✅ Run in PuTTY:
📌 Key Takeaway: LRU performs better than FIFO by keeping frequently used pages.
🔹 Optimal Page Replacement Algorithm
- Replaces the page that won’t be needed for the longest time.
- Best performance but requires future knowledge (not practical in real OS).
🛠 Python Program for Optimal Page Replacement
✅ Run in PuTTY:
📌 Key Takeaway: Optimal Algorithm has lowest page faults but is impractical in real OS since future references are unknown.
Thrashing & Memory Optimization
✅ 1. What is Thrashing?
Thrashing occurs when a system spends more time swapping pages in and out of memory than executing actual processes. This happens when the page fault rate is too high, causing severe performance degradation.
🔍 Causes of Thrashing
1️⃣ High Multiprogramming Level – Too many processes running, exceeding available memory.
2️⃣ Insufficient Frames – Processes require more frames than available, leading to excessive page faults.
3️⃣ Frequent Page Replacement – The system continuously swaps pages, consuming CPU resources.
🛠 Real-World Example:
- Imagine you are watching a YouTube video but your internet speed is too slow.
- Instead of playing smoothly, the video keeps buffering (similar to thrashing).
- The system is busy loading data instead of running the program efficiently.
✅ 2. Memory Optimization Techniques
To prevent thrashing, we use Memory Optimization techniques, including:
🔹 Working Set Model
- Maintains a fixed number of recent pages needed by a process.
- If the working set exceeds available frames, the system reduces the number of active processes.
🔹 Page Fault Frequency (PFF)
- Adjusts the number of allocated frames based on page fault rate.
- If faults increase, allocate more memory; if faults decrease, reduce memory allocation.
🛠 Practical: Implementing Page Replacement Algorithms in Python
Since thrashing occurs due to excessive page faults, optimizing page replacement can reduce thrashing.
Let’s implement FIFO, LRU, and Optimal page replacement algorithms.
🔹 FIFO Page Replacement Algorithm
✅ Run in PuTTY:
📌 Key Takeaway: FIFO can cause thrashing if frequently used pages are removed.
🔹 LRU (Least Recently Used) Page Replacement Algorithm
✅ Run in PuTTY:
📌 Key Takeaway: LRU prevents thrashing by keeping frequently used pages in memory.
🔹 Optimal Page Replacement Algorithm
✅ Run in PuTTY:
📌 Key Takeaway: Optimal Algorithm has the lowest page faults and reduces the chances of thrashing.
📌 Module 5: File Systems
✅ 1. File System Architecture
A file system is a method used by operating systems to store, retrieve, and organize data efficiently.
🔹 File System Components
1️⃣ Boot Control Block – Contains boot-related information.
2️⃣ Superblock – Holds metadata about the file system (size, blocks, inode count).
3️⃣ Inode Table – Stores file attributes (permissions, size, owner, timestamps).
4️⃣ Data Blocks – Store actual file content.
📌 Real-World Example:
Think of a library:
- Superblock = Library's catalog (book list, categories).
- Inodes = Each book’s metadata (title, author, location).
- Data Blocks = Actual books.
✅ 2. Directory Structure
A directory organizes files into a structured format. OS supports different directory structures:
🔹 Types of Directory Structures
1️⃣ Single-Level Directory – All files are in one directory (like a simple folder).
2️⃣ Two-Level Directory – Separate directories for each user.
3️⃣ Hierarchical (Tree) Directory – Like a file explorer with multiple subdirectories.
🛠 Python Program: Simulating Directory Structure
✅ Run in PuTTY:
📌 Key Takeaway: The hierarchical structure is widely used in modern OS (like Windows/Linux).
✅ 3. File Allocation Methods
When storing files, the OS needs to decide how to allocate disk space efficiently.
🔹 File Allocation Strategies
1️⃣ Contiguous Allocation – Stores a file in consecutive memory blocks (fast but may cause fragmentation).
2️⃣ Linked Allocation – Stores file blocks in scattered locations with links to the next block.
3️⃣ Indexed Allocation – Uses an index table to keep track of file block locations.
🛠 Python Program: Simulating File Allocation
✅ Run in PuTTY:
📌 Key Takeaway: Contiguous allocation is fast but may cause fragmentation, leading to wasted space.
📌 File Allocation Methods
When a file is stored on disk, the OS must decide how to allocate blocks efficiently.
✅ 1. Contiguous Allocation
- Files are stored in consecutive disk blocks.
- Fast access since disk heads don't need to move frequently.
- Problem: Leads to fragmentation (gaps between files).
🛠 Python Program: Contiguous Allocation
✅ Run in PuTTY:
📌 Key Takeaway: Contiguous allocation is fast but causes fragmentation.
✅ 2. Linked Allocation
- Each file is stored in scattered blocks, with a pointer to the next block.
- Efficient for dynamic files but slower due to extra lookups.
🛠 Python Program: Linked Allocation
✅ Run in PuTTY:
📌 Key Takeaway: No fragmentation, but slow access due to pointers.
✅ 3. Indexed Allocation
- A table (index) keeps track of file blocks.
- No fragmentation and fast access, but requires extra storage for the index table.
🛠 Python Program: Indexed Allocation
✅ Run in PuTTY:
📌 Key Takeaway: Fast random access, but extra space is needed for the index.
📌 Disk Scheduling Algorithms
Disk scheduling decides which I/O request to serve next to minimize seek time.
✅ 1. First-Come-First-Serve (FCFS)
- Requests are served in the order they arrive.
- Fair but inefficient for large requests.
🛠 Python Program: FCFS Disk Scheduling
✅ Run in PuTTY:
📌 Key Takeaway: Simple but can lead to long waiting times.
✅ 2. Shortest Seek Time First (SSTF)
- Picks the closest request to the current head position.
- Reduces seek time but causes starvation.
🛠 Python Program: SSTF Disk Scheduling
✅ Run in PuTTY:
📌 Key Takeaway: Fast but may cause starvation for distant requests.
✅ 3. SCAN (Elevator Algorithm)
- Moves in one direction, serving requests, then reverses.
- Efficient for large requests.
🛠 Python Program: SCAN Disk Scheduling
✅ Run in PuTTY:
📌 Key Takeaway: Balances fairness and efficiency.
✅ 4. LOOK Scheduling (Optimized SCAN)
- Similar to SCAN, but stops at the last request instead of going to the disk’s end.
🛠 Python Program: LOOK Scheduling
✅ Run in PuTTY:
📌 Key Takeaway: LOOK is more efficient than SCAN since it doesn’t go to the disk's end.
📌 Module 6: I/O Systems & Device Management
✅ 1. Device Drivers & I/O Scheduling
🔹 What are Device Drivers?
A device driver is a software component that allows the OS to interact with hardware devices. Examples:
- Keyboard Driver: Handles keystrokes.
- Printer Driver: Manages printing operations.
- Disk Driver: Controls HDD/SSD operations.
📌 Key Concepts:
- Character Devices (e.g., Keyboard, Mouse)
- Block Devices (e.g., Hard Disk, SSD)
- Network Devices (e.g., Ethernet, Wi-Fi)
✅ 2. Interrupt Handling
🔹 What is an Interrupt?
An interrupt is a signal that stops the CPU from its current execution to handle an urgent task.
📌 Types of Interrupts:
- Hardware Interrupts: Generated by hardware (e.g., keyboard press, mouse click).
- Software Interrupts: Triggered by a software program (e.g., system calls).
🔹 Example: Simulating an Interrupt in Python
✅ Run in PuTTY:
📌 Key Takeaway: The OS uses interrupt handlers to prioritize tasks efficiently.
✅ 3. Buffering, Spooling & Caching
🔹 What is Buffering?
- Buffering is temporary storage between a slow and fast device.
- Example: Copying files to a USB drive (data is buffered before writing).
🔹 Example: Implementing a Simple Buffer in Python
✅ Run in PuTTY:
📌 Key Takeaway: Buffering smoothens data transfer between devices.
🔹 What is Spooling?
- Spooling (Simultaneous Peripheral Operations On-Line) is a process where I/O operations are queued.
- Example: Printing multiple files (jobs are queued in the spooler).
🔹 Example: Implementing a Simple Spooling System
✅ Run in PuTTY:
📌 Key Takeaway: Spooling improves performance by queuing I/O operations.
🔹 What is Caching?
- Caching stores frequently accessed data for faster retrieval.
- Example: Web Browser Cache stores images for quick page loading.
🔹 Example: Implementing a Simple Cache in Python
✅ Run in PuTTY:
📌 Key Takeaway: Caching reduces access time by storing frequently used data.
🛠 Practical: Implement a Simple I/O Scheduling Algorithm
🔹 What is I/O Scheduling?
- The OS decides which I/O request to process first.
- Improves efficiency and disk performance.
🛠 Python Program: Simple I/O Scheduling (FCFS)
✅ Run in PuTTY:
📌 Key Takeaway: FCFS (First-Come-First-Serve) I/O Scheduling is fair but slow.
📌 Module 7: Inter-Process Communication (IPC)
✅ 1. Pipes & Named Pipes (FIFO)
🔹 What are Pipes?
- Pipes allow two processes to communicate by sending data from one to another.
- Pipes are unidirectional (data flows in one direction).
- Used for parent-child process communication.
📌 Example: Implementing IPC using Pipes in Python
✅ Run in PuTTY:
📌 Key Takeaway: Pipes enable communication between related processes.
🔹 What are Named Pipes (FIFO)?
- Named Pipes (FIFO) allow unrelated processes to communicate.
- FIFO files exist in the file system and persist after execution.
📌 Example: Implementing IPC using Named Pipes (FIFO)
Step 1: Create FIFO File
Step 2: Write a Python Program to Send Data
Step 3: Write a Python Program to Receive Data
✅ Run in PuTTY:
📌 Key Takeaway: Named Pipes (FIFO) enable communication between independent processes.
✅ 2. Message Passing (Message Queues)
🔹 What are Message Queues?
- Message queues allow processes to send and receive messages asynchronously.
- Unlike pipes, messages persist even if the receiver is not active.
📌 Example: Implementing IPC using Message Queues
✅ Run in PuTTY:
📌 Key Takeaway: Message queues enable asynchronous process communication.
✅ 3. Shared Memory
🔹 What is Shared Memory?
- Shared memory allows processes to directly share a memory space.
- Faster than pipes/message queues since no data copying occurs.
📌 Example: Implementing IPC using Shared Memory
✅ Run in PuTTY:
📌 Key Takeaway: Shared memory provides fast, efficient IPC but requires synchronization.
✅ 4. Remote Procedure Call (RPC)
🔹 What is RPC?
- RPC allows a process to call a function in another process (even on another machine).
- Used in distributed systems and cloud applications.
📌 Example: Implementing RPC using Python's xmlrpc
Server Code (rpc_server.py)
Client Code (rpc_client.py)
✅ Run in PuTTY:
📌 Key Takeaway: RPC allows communication between processes across networks.
📌 Module 8: Distributed Operating Systems
✅ 1. Characteristics of Distributed OS
A Distributed Operating System (DOS) manages a group of independent computers and makes them appear as a single system.
🔹 Key Characteristics
-
Transparency
- Access Transparency: Users can access remote resources as if they were local.
- Location Transparency: Users don’t need to know where a resource is physically located.
- Replication Transparency: The system handles data duplication automatically.
-
Fault Tolerance
- If one node fails, the system can redistribute tasks to ensure continuity.
-
Scalability
- A DOS can efficiently handle increasing workloads by adding more nodes.
-
Concurrency
- Multiple processes can run in parallel across different machines.
-
Security & Synchronization
- Mechanisms like authentication and locking are used to maintain consistency across nodes.
📌 Example: Understanding Distributed OS
Imagine Google Drive or Dropbox—you store a file, but it’s replicated across multiple servers. Even if one server fails, your file is still accessible.
✅ 2. Communication in Distributed Systems
Distributed Systems use inter-process communication (IPC) techniques to exchange data.
🔹 Methods of Communication
-
Message Passing
- Used for communication between remote processes.
- Example: Sockets, Remote Procedure Call (RPC).
-
Remote Procedure Call (RPC)
- A process can call a function on another system as if it were local.
- Example: gRPC, XML-RPC.
📌 Example: Simple Socket Programming for Distributed Communication Server Code (server.py)
Client Code (client.py)
✅ Run in PuTTY:
1️⃣ Start the Server:
2️⃣ Run the Client:
📌 Key Takeaway: Sockets enable process communication across different machines.
✅ 3. Distributed File System (NFS, HDFS)
A Distributed File System (DFS) allows files to be stored across multiple machines while appearing as a single file system.
🔹 Popular Distributed File Systems
-
Network File System (NFS)
- Used for remote file sharing in UNIX/Linux.
- Example: A user on Machine A can access a file on Machine B as if it were local.
-
Hadoop Distributed File System (HDFS)
- Used in Big Data & Cloud Computing.
- Stores large files across a cluster of machines.
📌 Example: Setting Up HDFS on Ubuntu/Linux 1️⃣ Install Hadoop
2️⃣ Format the HDFS NameNode
3️⃣ Start HDFS
4️⃣ Create a Directory in HDFS
📌 Key Takeaway: HDFS enables fault-tolerant, distributed file storage.
✅ 4. Distributed Synchronization & Coordination
In a distributed system, multiple nodes need to coordinate their operations.
🔹 Synchronization Mechanisms
-
Distributed Locks
- Prevents multiple processes from modifying the same resource.
- Example: Apache Zookeeper.
-
Leader Election
- Nodes elect a leader to manage a resource.
📌 Example: Using Zookeeper for Leader Election 1️⃣ Install Zookeeper
2️⃣ Start Zookeeper
3️⃣ Connect to Zookeeper
4️⃣ Create a Znode
📌 Key Takeaway: Distributed coordination ensures data consistency across nodes.
📌 Module 9: Security & Protection in OS
✅ 1. Authentication & Access Control
Authentication ensures that only authorized users can access system resources, while Access Control restricts their actions.
🔹 Authentication Methods
- Password-based authentication (Traditional, but weak against brute-force attacks)
- Multi-Factor Authentication (MFA) (Combines passwords with OTPs, biometrics, etc.)
- Biometric Authentication (Fingerprint, Face Recognition)
🔹 Access Control Models
- Mandatory Access Control (MAC) → Security levels define access permissions.
- Discretionary Access Control (DAC) → File owners decide who can access their files.
- Role-Based Access Control (RBAC) → Permissions are assigned based on user roles.
📌 Example: Implementing a Simple User Authentication System in Python
✅ Run this program on your Linux system via PuTTY and test authentication.
✅ 2. Encryption & Secure Communication
Encryption ensures data confidentiality, even if intercepted by an attacker.
🔹 Types of Encryption
- Symmetric Encryption (AES, DES) → Same key is used for encryption & decryption.
- Asymmetric Encryption (RSA, ECC) → Uses a public-private key pair for secure communication.
📌 Example: Encrypting & Decrypting Messages using AES
✅ Try this on Linux via PuTTY to understand real-time encryption.
✅ 3. Intrusion Detection & Prevention
Intrusion Detection Systems (IDS) monitor system activity and detect security threats.
🔹 Types of IDS
- Host-based IDS (HIDS) → Monitors system logs & files for suspicious activity.
- Network-based IDS (NIDS) → Monitors network traffic to detect attacks.
📌 Example: Detecting Suspicious Login Attempts in Python
✅ Modify this script to scan real system logs for security threats.
📌 Module 10: Real-Time & Embedded Systems
✅ 1. Characteristics of Real-Time OS (RTOS)
A Real-Time Operating System (RTOS) is designed for systems where time constraints are critical.
🔹 Key Characteristics:
- Deterministic Behavior → Tasks execute within predictable time limits.
- Preemptive Scheduling → Higher priority tasks can interrupt lower priority tasks.
- Minimal Latency → Quick response to external events.
- Concurrency → Multiple tasks run in parallel.
- Reliability & Fault Tolerance → Critical for aerospace, automotive, and medical devices.
🔹 Types of RTOS:
- Hard RTOS → Missing a deadline leads to system failure (e.g., Pacemakers, Airbags).
- Soft RTOS → Missing a deadline reduces performance but does not cause failure (e.g., Video Streaming).
✅ 2. Task Scheduling in RTOS
RTOS uses priority-based task scheduling to ensure timely execution.
🔹 Common Scheduling Algorithms:
- Rate Monotonic Scheduling (RMS) → Fixed priority based on task frequency.
- Earliest Deadline First (EDF) → Task with the closest deadline runs first.
- Priority Inheritance → Prevents priority inversion when a low-priority task holds a resource needed by a high-priority task.
📌 Example: Simulating Real-Time Task Scheduling in Python
✅ Run this script in Linux via PuTTY to understand priority scheduling.
✅ 3. Case Study: Linux-Based Embedded Systems
Many embedded devices run Linux-based OS due to its flexibility and stability.
🔹 Examples of Linux in Embedded Systems
- Raspberry Pi (Raspbian OS) → IoT & Robotics
- Android (Linux Kernel) → Smartphones & Tablets
- Automotive Grade Linux (AGL) → In-vehicle infotainment systems
📌 Example: Checking Real-Time Capabilities in Linux
✅ Try these commands in PuTTY to explore Linux kernel functionalities.
projecttt
Comments
Post a Comment