OS Notes
Quick-reference cheatsheet covering all major Operating System topics — process management, scheduling, synchronization, memory, file systems, and deadlocks in a concise, exam-ready format.
Introduction
This cheatsheet condenses the entire Operating Systems syllabus into quick-reference format. Use it for last-minute revision before exams, quick lookup during assignments, or as a study companion alongside your textbook. Every entry is designed to be scannable — find what you need in seconds.
Process Management
Process: A program in execution with its own address space, program counter, registers, and stack.
Process States:
PCB (Process Control Block) contains: PID, process state, program counter, CPU registers, memory limits, list of open files, scheduling priority, accounting info.
Process creation: fork() creates child (copy of parent), exec() replaces process image.
Context Switch: Save state of current process → Load state of next process. Overhead includes saving/restoring registers, flushing TLB, cache penalties.
CPU Scheduling
| Algorithm | Preemptive? | Starvation? | Key Feature |
|---|---|---|---|
| FCFS | No | No | Simple, convoy effect |
| SJF | No | Yes | Optimal avg waiting time (non-preemptive) |
| SRTF | Yes | Yes | Preemptive SJF |
| Priority | Both | Yes | Use aging to prevent starvation |
| Round Robin | Yes | No | Time quantum based, good response time |
| MLQ | Yes | Possible | Fixed priority between queues |
| MLFQ | Yes | No | Processes move between queues |
Key Formulas:
- Turnaround Time = Completion Time - Arrival Time
- Waiting Time = Turnaround Time - Burst Time
- Response Time = First CPU Time - Arrival Time
- Throughput = Processes Completed / Total Time
Optimal time quantum for RR: Too small = excessive context switches; too large = becomes FCFS. Typical: 10-100ms.
Process Synchronization
Race Condition: Multiple processes access shared data concurrently, and the outcome depends on execution order.
Critical Section Requirements:
- Mutual Exclusion — only one process in CS at a time
- Progress — if CS is free, a waiting process must be allowed in
- Bounded Waiting — limit on how many times others enter before a waiting process
Synchronization Tools:
| Tool | Type | Key Property |
|---|---|---|
| Mutex | Binary lock | Ownership (only locker can unlock) |
| Semaphore | Counter | No ownership, signal from any thread |
| Monitor | Language construct | Automatic mutual exclusion |
| Spinlock | Busy-wait lock | No context switch, wastes CPU |
Semaphore operations: wait(S): if S > 0, decrement; else block. signal(S): increment, wake one blocked process.
Classic Problems: Producer-Consumer, Readers-Writers, Dining Philosophers.
Deadlock
Four Necessary Conditions (ALL must hold simultaneously):
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular Wait
Handling Strategies:
- Prevention: Break one of the four conditions
- Avoidance: Banker's Algorithm (check safe state before allocation)
- Detection: Resource Allocation Graph (single instance), Matrix algorithm (multiple instances)
- Recovery: Kill processes or preempt resources
Banker's Algorithm: Need = Max - Allocation. System is safe if a safe sequence exists where each process can get its needed resources.
Memory Management
Logical vs Physical Address: Logical (virtual) generated by CPU; Physical exists on RAM. MMU translates between them.
Techniques:
| ├── Contiguous | Fixed partitioning, Variable partitioning |
| ├── Non-contiguous | Paging, Segmentation |
| └── Virtual Memory | Demand paging, Page replacement |
Paging:
- Logical address = [Page Number | Offset]
- Physical address = [Frame Number | Offset]
- Page Table maps page → frame
- No external fragmentation; possible internal fragmentation
Segmentation: Divides memory by logical units (code, data, stack). Variable-sized segments → external fragmentation possible.
Page Replacement Algorithms:
| Algorithm | Belady's Anomaly? | Optimal? | Practical? |
|---|---|---|---|
| FIFO | Yes | No | Simple |
| Optimal | No | Yes | Not implementable (future knowledge) |
| LRU | No | Near-optimal | Expensive (hardware support needed) |
| Clock | No | Approximates LRU | Practical and efficient |
Thrashing: Process spends more time paging than executing. Cause: insufficient frames. Solution: Working Set Model, decrease multiprogramming degree.
EAT with TLB: EAT = α × t + (1-α) × 2t, where α = hit ratio, t = memory access time.
File Systems
File Allocation Methods:
- Contiguous: Fast sequential/random access, external fragmentation
- Linked: No fragmentation, slow random access, pointer overhead
- Indexed: Fast random access, index block overhead
Directory Structures: Single-level → Two-level → Tree → Acyclic graph → General graph
Free Space Management: Bit vector, Linked list, Grouping, Counting
File Operations: Create, Open, Read, Write, Seek, Delete, Truncate
I/O Systems
I/O Methods:
- Programmed I/O — CPU polls device (busy waiting)
- Interrupt-driven I/O — device signals CPU when ready
- DMA — device transfers directly to memory, interrupts CPU when done
Disk Scheduling: FCFS, SSTF, SCAN (elevator), C-SCAN, LOOK, C-LOOK
Disk Access Time = Seek Time + Rotational Latency + Transfer Time
Virtual Memory
- Pages loaded on demand (demand paging)
- Valid/Invalid bit in page table indicates if page is in memory
- Page fault triggers: trap → find frame → disk read → update page table → restart instruction
- Copy-on-Write: forked processes share pages until one writes
Security Basics
Authentication: Verify identity (passwords, biometrics, tokens) Authorization: Determine permissions (ACLs, capabilities, RBAC) Access Control Models: DAC (owner controls), MAC (system enforces), RBAC (role-based)
Common Threats: Buffer overflow, privilege escalation, rootkits, ransomware
Linux Quick Reference
ps aux # List all processes
top / htop # Real-time process monitor
kill -9 PID # Force kill
chmod 755 file # Set permissions
df -h # Disk usage
free -m # Memory usage
lsof -i :PORT # What's using a port
grep -r "text" /path # Search in filesExam Tips
- For scheduling problems: always draw a Gantt chart first
- For page replacement: trace through the reference string step by step
- For Banker's algorithm: calculate Need matrix first, then find safe sequence
- For deadlock: check all four conditions — if any is absent, no deadlock
- For disk scheduling: draw the number line showing head position and request queue
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Operating System Cheatsheet.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, interview, preparation, system, cheatsheet
Related Operating Systems Topics