Operating Systems · All levels
Operating Systems Interview Preparation: Processes, Scheduling, Memory and Deadlocks
A compact revision of OS fundamentals asked in technical interviews — processes vs threads, CPU scheduling, synchronisation, deadlocks, paging and virtual memory.
Published 4 Dec 20263 min read
Operating systems questions check your understanding of how programs share the CPU and memory. Keep answers precise and use small examples.
Process vs thread
| Process | Thread | |
|---|---|---|
| Definition | A program in execution | A unit of execution inside a process |
| Memory | Own address space | Shares the process's memory |
| Creation / switch cost | Higher | Lower |
| Isolation | A crash usually doesn't affect others | A crash can bring down the whole process |
Process states: new → ready → running → waiting (blocked) → terminated.
Q: What is a context switch? Saving the state of the running process/thread (registers, program counter) and loading another's. It is pure overhead, so too many switches hurt performance.
CPU scheduling
| Algorithm | Idea | Note |
|---|---|---|
| FCFS | First come, first served | Simple; short jobs can wait behind long ones (convoy effect) |
| SJF / SRTF | Shortest job (remaining time) first | Minimises average waiting time; needs burst estimates; can starve long jobs |
| Priority | Highest priority first | Starvation risk; fixed with ageing |
| Round Robin | Each process gets a time quantum in turn | Fair and responsive; quantum size matters |
Key terms: turnaround time = completion − arrival; waiting time = turnaround − burst time.
Synchronisation
A race condition occurs when the result depends on the timing of concurrent access to shared data. The code that accesses shared data is the critical section.
- Mutex — a lock; only the thread that locked it should unlock it.
- Semaphore — a counter; a binary semaphore behaves like a lock, a counting semaphore allows up to N concurrent users.
Classic problems: producer–consumer, readers–writers, dining philosophers.
Deadlock
A deadlock requires all four Coffman conditions:
- Mutual exclusion
- Hold and wait
- No pre-emption
- Circular wait
Handling strategies: prevention (break one condition, e.g. always acquire locks in a fixed order), avoidance (Banker's algorithm), detection and recovery, or ignoring it (many general-purpose OSes leave it to applications).
Memory management
- Paging divides memory into fixed-size frames and processes into pages, mapped by a page table. It removes external fragmentation.
- Segmentation divides memory into variable-sized logical segments (code, stack, heap).
- TLB (translation lookaside buffer) caches recent page-table lookups to speed up address translation.
Virtual memory
Virtual memory lets a process use more memory than is physically available by keeping some pages on disk. Accessing a page not in RAM causes a page fault, and the OS loads it.
Page replacement algorithms: FIFO, Optimal (theoretical best), LRU (least recently used). Thrashing happens when the system spends more time swapping pages than doing work.
Other common questions
- Kernel vs user mode: privileged instructions run only in kernel mode; system calls switch from user to kernel mode.
- Fragmentation: internal (unused space inside an allocated block) vs external (free memory split into small unusable pieces).
- Starvation vs deadlock: starvation is indefinite waiting while others progress; deadlock is a cycle where no one progresses.
Practice checklist
- Compute average waiting time for FCFS, SJF and Round Robin on a sample process table.
- Explain how ordered lock acquisition prevents deadlock.
- Trace LRU page replacement for a short reference string.
- #operating-systems
- #cs-fundamentals