Operating Systems (OS) – One Shot Notes for Placement Interviews
By Anshika Chaudhary
For anyone preparing for placement interviews, internship interviews or university exams, these comprehensive yet concise notes provide a thorough overview of essential Operating Systems concepts. This guide covers fundamental topics like OS types, process and memory management, CPU scheduling, and critical algorithms. Download these notes to boost your preparation!
1. Introduction to Operating Systems
- Definition: An Operating System (OS) is system software that acts as an intermediary between the user and hardware, managing resources effectively.
- Key Functions:
- Resource management (CPU, memory, devices)
- File management
- Process management
- Security and access control
- User interface
2. Types of Operating Systems
- Batch Operating System: Groups jobs into batches; executes without user interaction.
- Time-Sharing OS: Multiple users access the system simultaneously, each with a time slice.
- Distributed OS: Multiple computers work together as a unified system to complete tasks.
- Real-Time OS (RTOS): Systems requiring immediate response, often used in embedded systems.
- Multiprogramming & Multitasking OS: Allows multiple programs in memory, managing their execution.
3. Process Management
- Process: A program in execution, containing code, stack, heap, and data sections.
- Process States: New, Ready, Running, Waiting (Blocked), Terminated
- Process Control Block (PCB): A structure containing process details (ID, state, CPU registers).
4. CPU Scheduling Algorithms
- First-Come, First-Served (FCFS): Executes processes in arrival order.
- Advantage: Simple
- Disadvantage: Convoy effect delays shorter processes
- Shortest Job Next (SJN): Selects shortest CPU burst time.
- Advantage: Minimizes average waiting time
- Disadvantage: Can starve longer processes
- Round Robin (RR): Processes receive equal time slices.
- Advantage: Fair for all processes
- Disadvantage: Performance varies by time slice length
- Priority Scheduling: CPU allocated based on priority.
- Advantage: Quick response for important tasks
- Disadvantage: Potential starvation of low-priority processes (solvable with aging)
5. Memory Management
- Purpose: Ensures efficient memory allocation, preventing memory leaks.
- Contiguous Memory Allocation: Allocates memory in a single block; can suffer from fragmentation.
- Paging: Splits memory into fixed-size pages, reducing external fragmentation.
- Advantage: No external fragmentation
- Disadvantage: Internal fragmentation
- Segmentation: Divides memory by logical sections (code, stack, data).
- Virtual Memory: Enables execution of processes partially in memory using disk as an extension.
6. Deadlock
- Definition: Occurs when processes indefinitely block each other.
- Conditions:
- Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait
- Prevention: Break any of the four conditions.
- Avoidance: Algorithms like the Banker’s Algorithm maintain a safe state.
- Detection & Recovery: Detect and recover by terminating processes or preempting resources.
7. Process Synchronization
- Critical Section Problem: Code sections where shared resources are accessed by multiple processes.
- Solution Requirements: Mutual Exclusion, Progress, Bounded Waiting
- Semaphores: Controls resource access.
- Mutexes: A type of semaphore for locking critical sections.
8. Page Replacement Algorithms (Virtual Memory Management)
- First In, First Out (FIFO): Oldest page is replaced.
- Disadvantage: Belady’s anomaly (more frames increase page faults)
- Least Recently Used (LRU): Replaces least-used page.
- Advantage: Approximates optimal replacement
- Disadvantage: Implementation complexity
- Optimal Replacement: Replaces page not needed for the longest time (theoretical).
9. Disk Scheduling Algorithms
- First-Come, First-Served (FCFS): Services requests in order of arrival.
- Advantage: Simple and fair
- Disadvantage: High seek times
- Shortest Seek Time First (SSTF): Prioritizes nearest disk head request.
- Advantage: Reduces seek time
- Disadvantage: Starvation risk for distant requests
- SCAN (Elevator): Head moves one direction servicing requests, then reverses.
- Advantage: Efficient, eliminates starvation
- LOOK: Variation of SCAN; head only moves as far as the last request.
10. Virtual Memory
- Demand Paging: Loads pages on request.
- Page Faults: Triggered when a page isn’t in memory.
- Thrashing: Excessive page swapping reduces process execution efficiency.
11. Processes and Threads
- Process: A program being executed, tracked by a Process Control Block (PCB).
- Arrival Time: Entry time to the queue.
- Completion Time: Execution completion.
- Burst Time: CPU execution time.
- Turnaround Time = Completion – Arrival.
- Waiting Time = Turnaround – Burst.
- Thread: Independent execution within a process, sharing code and data with other threads.