Operating System Notes for Interview Preparation
1. Process Management
A process is a program in execution, consisting of the program code and its activity. The OS manages the life
cycle of processes through states like:
- New: Process is being created.
- Ready: Process is ready to run but waiting for CPU.
- Running: Instructions are being executed.
- Waiting: Process is waiting for an event (like I/O).
- Terminated: Process has finished execution.
Context Switching is the mechanism that allows the CPU to switch from one process to another, storing the
state of the current process and loading the state of the next.
Scheduling Algorithms determine how processes are assigned to the CPU:
- FCFS (First Come First Serve): Processes are scheduled in the order of arrival.
- SJF (Shortest Job First): Executes shortest job first, optimal but hard to predict.
- Round Robin: Each process gets equal time in rotation.
- Priority Scheduling: Each process has a priority; higher priority runs first.
2. Threads and Concurrency
A thread is the smallest unit of execution within a process. A process can have multiple threads
(multithreading) sharing memory and resources.
Concurrency involves multiple threads making progress simultaneously. Issues in concurrency include:
- Race Conditions: Multiple threads access shared data simultaneously, leading to unpredictable results.
Operating System Notes for Interview Preparation
- Deadlock: Threads block each other by holding resources the other needs.
- Starvation: A thread waits indefinitely due to unequal resource allocation.
Synchronization tools like Mutex (mutual exclusion), Semaphores, and Monitors help coordinate thread
execution and protect shared data.
3. Memory Management
Memory management ensures efficient use of RAM by allocating space to processes.
- Paging: Memory is divided into fixed-size blocks (pages). Logical memory pages map to physical memory
frames.
- Segmentation: Memory is divided based on logical divisions like functions or data segments.
- Virtual Memory: Allows programs to use more memory than physically available by storing data temporarily
on disk.
- Page Replacement Algorithms (e.g., LRU, FIFO) are used when memory is full.
4. File System
A file system organizes and stores data on storage devices.
- File Operations: Create, Read, Write, Delete, Open, Close.
- Directory Structures:
- Single-level: One directory for all files.
- Two-level: Separate directory per user.
- Tree: Hierarchical directories.
Operating System Notes for Interview Preparation
- DAG: Allows shared subdirectories or files.
File Allocation Methods:
- Contiguous Allocation: Files occupy contiguous blocks.
- Linked Allocation: Each block points to the next.
- Indexed Allocation: A separate index block contains pointers to all file blocks.
5. Deadlocks
Deadlock is a situation where processes are stuck waiting for each other, preventing progress.
Four conditions for deadlock:
1. Mutual Exclusion: Resources are non-shareable.
2. Hold and Wait: Holding one resource, waiting for another.
3. No Preemption: Resources can't be forcibly taken.
4. Circular Wait: Circular chain of processes waiting.
Deadlock Handling:
- Prevention: Design system to prevent one of the four conditions.
- Avoidance: Use algorithms like Banker's Algorithm to avoid unsafe states.
- Detection & Recovery: Detect deadlock and recover by terminating or rolling back processes.
6. I/O Systems
I/O Systems manage communication between CPU and external devices.
Operating System Notes for Interview Preparation
- Interrupts signal the CPU to handle I/O events.
- Device Drivers provide an interface between OS and hardware.
- DMA (Direct Memory Access) allows devices to access memory without CPU involvement.
I/O Scheduling determines order of I/O requests. Buffering stores data temporarily to manage speed
mismatch between devices.
7. System Calls and OS Structure
System calls are the interface between user programs and OS services.
Types:
- Process Control (fork, exec, exit)
- File Management (open, read, write, close)
- Device Management (ioctl, read, write)
- Information Maintenance (getpid, alarm)
- Communication (pipe, shmget, socket)
OS Structures:
- Monolithic: All services in one large block (e.g., UNIX).
- Layered: OS functions in layers with clear interfaces.
- Microkernel: Only essential components in kernel; others in user space.
- Modular: OS components as loadable modules (e.g., Linux kernel modules).