1. What is an OS?
An Operating System is system software that manages hardware and provides services to applications.
Main functions
- Process management
- Memory management
- File system
- I/O & device management
- Security & protection
Types: Batch, Time-sharing, Real-time, Distributed, Mobile OS
2. Process vs Thread
Process
- Independent program in execution
- Own address space, PCB
- Heavy context switch
Thread
- Lightweight unit inside a process
- Shares code/data/heap of process
- Own stack & registers
- Faster context switch
Multithreading advantages: responsiveness, resource sharing, economy, scalability on multi-core.
Interview favorite: difference between process & thread, user-level vs kernel-level threads.
3. CPU Scheduling
Goals: maximize CPU utilization & throughput, minimize waiting & turnaround time.
Algorithms
- FCFS — simple, convoy effect
- SJF / SRTF — optimal avg waiting (but starvation)
- Round Robin — fair, quantum critical
- Priority — aging to avoid starvation
- Multilevel Queue / Feedback
Formulas
- Turnaround = Completion − Arrival
- Waiting = Turnaround − Burst
- Response = First CPU − Arrival
Exam tip: Always draw Gantt chart for numericals.
4. Deadlocks
Coffman conditions (all 4 needed)
1. Mutual Exclusion
2. Hold and Wait
3. No Preemption
4. Circular Wait
Handling
- Prevention — break one condition
- Avoidance — Banker's Algorithm
- Detection — wait-for graph / resource allocation graph
- Ignore — Ostrich approach (used by many OSes)
Banker's: need ≤ available for safe sequence.
5. Memory Management
Contiguous: fixed/variable partitions, external fragmentation
Non-contiguous: Paging, Segmentation
Paging
- Logical address = page number + offset
- Page table maps to frames
- Internal fragmentation possible
Virtual Memory
- Demand paging, thrashing
- Page fault → OS loads page from disk
Page Replacement
- FIFO — Belady's anomaly possible
- Optimal — theoretically best
- LRU — practical approximation of Optimal
- Clock / Second chance