OS_Interview_Notes
Fundamental Concepts
1. What is an Operating System?
An OS is system software that manages hardware resources (CPU, memory, disk,
peripherals) and allows applications to run. It acts as an intermediary between
users and hardware.
Main functions:
- Process/CPU scheduling and management
- Memory allocation and management
- File system management
- Device input/output management
- Security and user access control
- Interrupt and exception handling
2. What are the main differences between Process and
Thread?
Aspect Process Thread
Share same process
Memory Separate memory space for each
memory
Creation Slower (more resource allocation) Faster (lightweight)
Resource overhead High Low
IPC mechanisms needed (pipes,
Communication Direct via shared memory
sockets)
Crash affects whole
Isolation Isolated, crash doesn’t affect others
process
Context switch
Slow (full state save/restore) Fast (minimal state)
time
OS_Interview_Notes 1
When to use: Use processes for independent tasks, threads for concurrent tasks
within same application.
3. What is a Kernel and Kernel Mode?
The kernel is the core part of OS that directly manages hardware. It’s the most
privileged part running in kernel mode with unrestricted hardware access.
Kernel responsibilities:
- CPU scheduling and process management
- Memory management and protection
- Interrupt/exception handling
- Device driver management
- File system operations
Kernel Mode vs User Mode:
- Kernel Mode: Full hardware access, can execute any instruction, direct device
access (dangerous)
- User Mode: Restricted access, safe (can’t directly access hardware), needs
system calls for OS services
Kernel Types:
- Monolithic: All services in kernel space (Linux, Windows) - fast but if crash =
entire system fails
- Microkernel: Only essentials in kernel, other services in user space (QNX) -
stable but slower due to extra context switches
4. What is a Process?
A process is a program in execution - the runtime instance of a program with its
own memory and resources.
What a process contains:
- Memory sections: Code, data, heap, stack
- Process Control Block (PCB): Contains process ID, state, program counter, CPU
registers, memory tables
- Resources: File descriptors, I/O devices, signal handlers
Process States:
OS_Interview_Notes 2
New → Ready ↔ Running → Terminated
↑ ↓
└─ Waiting ─┘
New: OS is initializing the process
Ready: Has everything needed, waiting for CPU time
Running: Currently executing on CPU
Waiting: Waiting for I/O or some event
Terminated: Finished execution, OS cleaning up resources
5. What is a Thread?
A thread is a lightweight execution unit within a process - smallest unit the OS
can schedule.
Key differences from processes:
- Multiple threads share the same memory space of a process
- Threads share heap, global variables, file descriptors
- Each thread has its own stack and registers
- Much faster to create than processes
- Context switching between threads is faster
Example: Chrome browser = 1 process with multiple threads (rendering thread,
download thread, UI thread, etc.)
Advantages of threading:
- Responsive applications (one thread can work while other waits)
- Resource sharing (lighter than multiple processes)
- Better multicore utilization
6. What is Scheduling? Explain different CPU
Scheduling Algorithms
Scheduling is deciding which process gets the CPU when multiple processes are
ready.
OS_Interview_Notes 3
FCFS (First Come First Served)
- Simplest algorithm - processes execute in order they arrive
- Non-preemptive (once running, keeps CPU until done)
- Pros: Simple, no starvation
- Cons: Long process makes all others wait (convoy effect), poor average waiting
time
Example: P1(10ms) → P2(1ms) = P2 waits 10ms (bad!)
SJF (Shortest Job First)
- Runs process with shortest burst time first
- Optimal average waiting time
- Pros: Minimizes average waiting time
- Cons: Can’t know burst time in advance, short jobs keep coming = long jobs
starve
Example: P1(8ms), P2(4ms), P3(2ms) → P3→P2→P1 = better waiting time
Priority Scheduling
- Each process gets a priority; higher priority runs first
- Can be preemptive or non-preemptive
- Pros: Important tasks can be prioritized
- Cons: Low priority processes can starve indefinitely
Solution: Use aging - gradually increase priority of waiting processes
Round Robin (RR)
- Each process gets a fixed time slice (quantum) - typically 4-100ms
- When time expires, process goes to back of queue
- Pros: Fair distribution, no starvation, responsive
- Cons: Higher context switching overhead, if quantum too small = overhead
dominates
7. What is Context Switching?
Context switching is the process of switching CPU from one process/thread to
another.
Steps:
1. Save current process’s context (registers, program counter, memory info) into
PCB
OS_Interview_Notes 4
2. Select next process
3. Load next process’s context from its PCB
4. Resume execution
Cost of context switching:
- Direct cost: Time to save/restore state (microseconds)
- Indirect cost: Cache misses (new process uses different memory = cold cache)
Context switching is necessary for multitasking but expensive. Too many switches
= reduced efficiency.
8. Virtual Memory - Explanation and Importance
Virtual memory makes programs think they have more memory than physically
available by using disk storage as extension of RAM.
How it works:
- Programs use virtual addresses (not physical)
- Memory Management Unit (MMU) translates to physical addresses
- If accessed data not in RAM, page fault occurs
- OS loads page from disk to RAM
Benefits:
- Programs appear to have unlimited memory
- Better utilization of physical memory
- Easier programming (no need to manage physical memory)
- Process isolation and security
- Supports multiprogramming efficiently
Trade-off: Disk is very slow, so page faults slow down system
Page Fault: When process accesses memory not currently in RAM
- OS interrupts program
- Loads required page from disk to RAM
- Resumes program
9. Paging and Segmentation
Paging:
- Divides physical memory into fixed-size frames (typically 4KB)
OS_Interview_Notes 5
- Virtual memory divided into same-size pages
- OS maintains page table mapping virtual pages to physical frames
- No external fragmentation (only internal - page doesn’t fill completely)
Segmentation:
- Divides memory into variable-sized segments based on program structure
- Segments represent logical units (code, data, stack)
- Programmer visible
- External fragmentation problem (gaps between segments)
10. Page Replacement Algorithms
When physical memory full and new page needed, which page to remove?
FIFO (First In First Out)
- Remove oldest page in memory
- Simple to implement
- Problem: Can perform poorly (Belady’s anomaly - increasing frames increases
faults)
LRU (Least Recently Used)
- Remove page not used for longest time
- Pros: Better performance than FIFO
- Cons: Needs timestamp tracking (overhead)
Optimal (Belady’s)
- Remove page that won’t be used for longest time in future
- Theoretically best (fewest page faults)
- Problem: Impossible in practice (need future knowledge)
- Use: As benchmark to evaluate other algorithms
Clock Algorithm (Second Chance)
- Approximates LRU with less overhead
- Pages have reference bit - set to 1 when accessed
- On replacement: find first page with bit=0, if bit=1 set to 0 and continue
- Simpler than LRU but good performance
11. Thrashing
OS_Interview_Notes 6
Thrashing = System spends more time paging (disk I/O) than executing programs.
What happens:
- Process needs page not in memory
- OS loads page, removes another
- New page also missing, faults again
- Constant disk activity, very slow performance
Causes:
- Too many processes for available memory
- Working set (actively used pages) > physical memory
Symptoms:
- System extremely slow
- Disk constantly active
- CPU usage high but nothing happening
Solutions:
- Reduce number of processes
- Increase RAM
- Use better page replacement algorithm
- Working set model: Ensure each process’s working set fits in memory
12. Deadlock - Concept and 4 Necessary Conditions
Deadlock = Two or more processes stuck forever, each waiting for resource held
by other.
Example:
Process A: Has Resource 1, wants Resource 2
Process B: Has Resource 2, wants Resource 1
→ Both wait forever (DEADLOCK)
4 Necessary Conditions (ALL must be present):
1. Mutual Exclusion: Resource can only be held by one process at a time
2. Hold and Wait: Process can hold one resource while waiting for another
OS_Interview_Notes 7
3. No Preemption: Can’t forcibly take resource from process (only process can
release)
4. Circular Wait: Circular chain of processes, each waiting for resource held by
next
13. Deadlock Prevention and Avoidance
Prevention: Remove one of the 4 conditions
Remove Mutual Exclusion: Not practical (some resources must be exclusive)
Remove Hold and Wait: Acquire ALL resources at once before executing.
Problem: Process might not need all simultaneously
Remove No Preemption: Allow forcible resource taking. Problem: Data
corruption possible
Remove Circular Wait: Impose ordering - all processes must request
resources in same order. Practical solution
Avoidance: Use algorithms like Banker’s Algorithm
- Before granting resource, check if it would lead to unsafe state
- If safe, grant; if not, wait
- Requires knowing max resource needs in advance
Detection: Let deadlock happen, then:
- Detect using resource allocation graph (cycle = deadlock)
- Recover by terminating one or more processes
Practical approach: Most systems ignore deadlock (Ostrich algorithm) because
prevention is costly
14. Process Synchronization - Critical Section Problem
Critical Section: Code section where process accesses shared resource.
Problem: Multiple processes in critical section simultaneously → data
corruption/inconsistency
Example:
OS_Interview_Notes 8
Shared: count = 0
Process A: Process B:
read count (0) read count (0)
count = count+1 count = count+1
write count (1) write count (1)
Result: count = 1 (should be 2!) - RACE CONDITION
Solution: Ensure only ONE process in critical section at a time using:
- Locks (mutex, semaphore)
- Atomic operations
- Monitors
15. Semaphore and Mutex
Semaphore:
- Integer variable with atomic operations
- Two operations:
- wait(S): S–; if S<0, process blocks
- signal(S): S++; wake one waiting process
Binary Semaphore (value 0 or 1): Acts like lock/unlock
Counting Semaphore (value>1): Controls access to resource pool
Example:
Semaphore mutex = 1
Process A:
wait(mutex) // Acquire
critical_section()
signal(mutex) // Release
Process B:
wait(mutex) // Blocks if A has it
OS_Interview_Notes 9
critical_section()
signal(mutex)
Mutex (Mutual Exclusion):
- Simpler than semaphore
- Only for mutual exclusion
- Only process holding lock can release it (safer)
- Two states: locked/unlocked
Difference:
- Semaphore: More general (signaling + mutual exclusion), any process can signal
- Mutex: Specifically for mutual exclusion, only holder releases
16. Race Condition
Race condition = Multiple processes access shared data and result depends on
execution order.
Example:
Shared: x = 0
Thread A: x = x + 1 (read x=0, add 1, write x=1)
Thread B: x = x + 1 (read x=0, add 1, write x=1)
Timeline (race):
A: read x(0)
B: read x(0) ← Both read 0
A: write x(1)
B: write x(1) ← Both write 1
Result: x = 1 (should be 2!)
Fix: Synchronize with locks to ensure atomicity
17. User Mode vs Kernel Mode
OS_Interview_Notes 10
Aspect User Mode Kernel Mode
Access Limited (can’t access hardware directly) Full (all resources)
Who runs User applications OS kernel code
Privilege level Lower (restricted) Higher (unrestricted)
Instruction set Limited instructions Full instruction set
Memory access Own memory space only All memory
I/O access Cannot directly access devices Can access all devices
Error handling Errors contained to process Errors can crash system
Speed Slightly slower (needs system calls) Faster (direct access)
Transition:
- User mode → Kernel mode: System call (trap instruction)
- Kernel mode → User mode: After system call completes
18. System Call
System call = Request from user program to OS kernel for services
Why needed:
- User programs can’t directly access hardware (dangerous)
- OS provides controlled interface for hardware access
Process:
1. User program calls system call
2. CPU switches to kernel mode
3. OS executes operation
4. CPU switches back to user mode
5. Returns result to program
Common system calls:
- File I/O: open(), read(), write(), close()
- Process: fork(), exec(), wait(), exit()
- Memory: brk(), mmap()
- IPC: pipe(), socket()
19. Interrupt and Exception Handling
OS_Interview_Notes 11
Interrupt = Signal causing CPU to pause current execution
Types:
- Hardware Interrupts: From devices (keyboard, disk, network, timer)
- Software Interrupts: From instructions (system calls, exceptions)
Process:
1. Interrupt signal generated
2. CPU saves current context
3. CPU transfers to interrupt handler (via interrupt vector)
4. Handler processes interrupt
5. CPU resumes interrupted program
Interrupt Vector: Table mapping interrupt numbers to handler addresses - allows
quick lookup
Interrupt Service Routine (ISR): The handler code for specific interrupt
20. Memory Fragmentation
Internal Fragmentation:
- Wasted space within allocated memory block
- Example: Need 10KB, allocate 16KB page → 6KB wasted internally
- Caused by fixed-size allocation
External Fragmentation:
- Wasted space between allocated blocks
- Example: Free blocks scattered, can’t fit large process even with total free space
available
- Caused by variable-size allocation
Paging issues: Internal fragmentation
Segmentation issues: External fragmentation
Solutions:
- Paging: Mostly avoids (except internal)
- Segmentation: Compaction (rearrange memory)
21. Starvation
OS_Interview_Notes 12
Starvation = Process never gets CPU/resources it needs, usually due to unfair
scheduling.
Example:
- High-priority processes keep arriving
- Low-priority process never gets scheduled
- Low-priority process starves indefinitely
Difference from deadlock:
- Deadlock: Processes blocked waiting for resources held by each other
- Starvation: Process ready but never chosen by scheduler
Solution:
- Aging: Gradually increase priority of waiting processes over time
- Fair scheduling (Round Robin)
- Priority adjustment based on wait time
22. Multiprogramming vs Multitasking vs
Multiprocessing
Multiprogramming:
- Multiple programs in memory simultaneously
- When one waits for I/O, CPU switches to another
- Increases CPU utilization (no idle time)
- Single CPU, appears sequential
Multitasking:
- Multiple programs appear to run simultaneously
- CPU rapidly switches between them
- User perceives parallel execution
- Single CPU, actually sequential but very fast
Multiprocessing:
- Multiple CPUs/cores
- Programs actually execute in parallel
- True simultaneous execution
23. IPC (Inter-Process Communication)
OS_Interview_Notes 13
How processes communicate and share data:
Pipes:
- One-way communication channel
- Process A writes, Process B reads
- Common in Unix/Linux
- Example: cat [Link] | grep "pattern"
Shared Memory:
- Multiple processes access same memory region
- Fastest IPC (no copying)
- Needs synchronization (semaphore/mutex)
Sockets:
- Two-way communication
- Can be on same machine or over network
- Used for networking
Message Queues:
- Processes put messages in queue
- Other processes read from queue
- Asynchronous, decoupled communication
Signals:
- Software interrupts
- One process sends signal to another
- Simple but limited (just signal number)
24. Booting Process
1. Power On: Computer powers up
2. POST (Power On Self Test): BIOS checks hardware
3. Bootstrap: BIOS loads bootloader from disk (usually MBR)
4. Bootloader: Loads OS kernel into memory
5. Kernel initialization:
Initialize interrupt handlers
OS_Interview_Notes 14
Initialize device drivers
Set up memory management
6. OS loads:
Loads shell (CLI) or GUI
Ready for user commands
25. File System Organization
Hierarchical structure: Root → directories/folders → files
File Operations:
- Create, Open, Read, Write, Close, Delete, Append, Seek
File Attributes (Metadata):
- Name, size, creation/modification date
- Owner and permissions
- File type, location on disk
Directory structure:
- Directories contain files and subdirectories
- Each file has unique path
- Allows logical organization
File Allocation Methods:
- Contiguous: All blocks consecutive (fast but fragmentation)
- Linked: Blocks can be scattered, linked via pointers (flexible but slower)
- Indexed: Index block points to all data blocks (balanced)
26. Disk Scheduling Algorithms
When multiple I/O requests queue, which disk request to serve first?
FCFS (First Come First Served)
- Serve requests in order they arrive
- Simple but poor performance
- Disk head moves randomly across disk
OS_Interview_Notes 15
SSTF (Shortest Seek Time First)
- Serve request closest to current head position
- Pros: Faster than FCFS
- Cons: Inner tracks starve
SCAN (Elevator Algorithm)
- Disk head moves in one direction, serving all requests
- At end, reverses direction
- Fair, efficient
C-SCAN (Circular SCAN)
- Like SCAN but head returns to beginning after end
- More uniform wait time
27. Real-Time Operating System (RTOS)
OS designed for applications with strict timing requirements.
Hard Real-Time:
- Missing deadline = catastrophic failure
- Examples: Aircraft control, medical pacemaker, airbag systems
Soft Real-Time:
- Missing deadline = undesirable but tolerable
- Examples: Video playback, online games, video conferencing
Firm Real-Time:
- Missing deadline wastes value but doesn’t cause critical failure
- Examples: Some industrial control systems
Characteristics:
- Predictable, bounded response times
- Priority-based preemptive scheduling
- Minimal latency and overhead
- Deterministic behavior
28. Zombie vs Orphan Process
Zombie Process:
- Child process finished but parent hasn’t collected exit status
OS_Interview_Notes 16
- Entry remains in process table
- Using system resources
- Cause: Parent terminated before waiting for child
Fix: Parent must call wait() to collect child’s exit status
Orphan Process:
- Child process’s parent terminated
- Child becomes child of init process (PID 1)
- Difference: Orphan is still running, zombie is dead
Example:
Parent creates Child
Parent exits without calling wait()
Child becomes Zombie (entry remains)
vs
Parent exits suddenly
Child becomes Orphan (adopted by init)
29. Monolithic vs Microkernel Architecture
Monolithic Kernel:
- All OS services in kernel space (file system, drivers, networking)
- Single large program running in kernel mode
- Examples: Linux, Unix, Windows (with modifications)
Pros:
- Fast (no context switching for system calls)
- Simple design
Cons:
- One bug crashes entire system
- Hard to maintain (large code)
- Hard to add new features
Microkernel:
- Only essential services in kernel (IPC, memory, scheduling)
OS_Interview_Notes 17
- Other services in user space
- Examples: QNX, MINIX, Mac OS X kernel
Pros:
- More reliable (one service crash ≠ system crash)
- Easier maintenance
- Better security (services limited privileges)
- Flexible
Cons:
- Performance overhead (more IPC calls)
- More complex
- Slower than monolithic
30. Virtualization and Containerization
Virtualization:
- Running multiple complete OSes on single hardware
- Hypervisor abstracts hardware
- Each VM has own OS, filesystem, resources
- Examples: VirtualBox, VMware, Hyper-V
Pros: Isolation, resource sharing, testing
Cons: Heavy (full OS overhead), slower startup
Containerization:
- Package application + dependencies in container
- Multiple containers share host OS kernel
- Lighter than VMs, faster startup
- Examples: Docker, Kubernetes
Pros: Lightweight, fast, portable
Cons: Less isolation than VMs, all containers use same OS kernel
Most Important Topics (Most Frequently Asked)
These MUST be known:
1. Process vs Thread - Asked in 90%+ of interviews
OS_Interview_Notes 18
2. Scheduling Algorithms - Very common, compare them
3. Deadlock - Classic question with follow-ups
4. Virtual Memory & Paging - Fundamental concept
5. Process Synchronization - Semaphore, mutex, race conditions
6. Memory Management - Fragmentation, page replacement
7. Context Switching - Why and cost
8. CPU Modes - User vs kernel mode
Also important:
- System calls and interrupts
- IPC mechanisms
- File systems
- Monolithic vs microkernel
- Thrashing and working set
Interview Tips
✓ Understand concepts deeply - Know “why” not just “what”
✓ Use examples - Concrete examples help explanation
✓ Draw diagrams - Visual representations are powerful (process states,
scheduling timeline, page table)
✓ Compare algorithms - Always discuss pros/cons and when to use each
✓ Mention trade-offs - No perfect solution, show understanding
✓ Link to real world - Relate to Linux/Windows
✓ Ask clarifying questions - Shows you think before answering
✓ Be confident but honest - If you don’t know, say no rather than guessing
OS_Interview_Notes 19