Operating Systems interview questions & answers
Processes, threads, memory and concurrency. Practice clear explanations, realistic scenarios and follow-up questions for interviews.
Official reference: Operating Systems: Three Easy Pieces
8 Operating Systems interview questions study by subtopic
1.How does a process differ from a thread?mid
A process is an execution environment with its own virtual address space and resources. Threads within a process share that address space but have their own stacks and execution state. Sharing memory makes communication convenient and introduces synchronization risks. Processes generally provide stronger isolation, while threads can be useful for concurrent work inside an application. The costs of creation and scheduling depend on the operating system and runtime.
What interviewers listen for- Processes have separate address spaces
- Threads share process memory
- Threads have separate stacks
- Sharing requires synchronization
Likely follow-up: When would you choose worker processes over threads?
2.What causes deadlock and how can you prevent it?hard
Deadlock occurs when participants wait indefinitely for resources held by one another. The classic conditions are mutual exclusion, holding resources while waiting, no forced preemption and circular wait. A consistent global lock acquisition order can break circular wait. Other approaches include reducing lock scope or avoiding holding one lock while acquiring another. Timeouts help detect or escape a wait, but recovery must release resources and preserve invariants.
What interviewers listen for- Explain a circular wait
- Identify the four conditions
- Use consistent lock ordering
- Recover without corrupting state
Likely follow-up: How is deadlock different from starvation?
3.Why do operating systems use virtual memory?mid
Virtual memory gives processes an address space that is mapped to physical memory through page tables. It supports isolation, protection and flexible allocation without requiring contiguous physical memory. A page fault means a mapping needs attention; it does not always mean disk I/O, because demand-zero allocation or copy-on-write can also fault. Heavy paging can make a system slow, so I would inspect memory pressure and the working set before simply adding threads.
What interviewers listen for- Virtual addresses map to physical pages
- Memory protection isolates processes
- Page faults have multiple causes
- Working sets affect performance
Likely follow-up: What happens when a process repeatedly accesses more memory than RAM can hold?
4.How do concurrency and parallelism differ?easy
Concurrency means multiple tasks can make progress over overlapping periods; parallelism means tasks execute at the same time. A single CPU core can support concurrency by switching between tasks. Multiple cores can enable parallel execution, subject to runtime constraints and workload structure. I would use concurrency to overlap waiting and parallelism to accelerate divisible computation. Both require care with shared state, and overhead can outweigh the benefit for small tasks.
What interviewers listen for- Concurrency is overlapping progress
- Parallelism is simultaneous execution
- One core can support concurrency
- Match the approach to workload and overhead
Likely follow-up: Can an application be concurrent without being parallel?
5.How would you investigate a process whose memory keeps growing?mid
Measure memory over a repeatable workload and distinguish a temporary peak or cache warmup from sustained growth. Compare heap snapshots or allocation profiles to find objects that remain reachable unexpectedly. Also inspect native allocations, open resources and memory mappings because heap metrics may not explain the full resident size. Look for unbounded caches, retained listeners and queues. Confirm a fix by repeating the same workload and observing a stable memory trend.
What interviewers listen for- Reproduce and measure the trend
- Inspect retained allocations
- Include native memory and resources
- Verify stabilization after the fix
Likely follow-up: Why can memory leak in a garbage-collected language?
6.What trade-offs does a scheduler make when choosing a time slice?mid
Short time slices can improve responsiveness by giving runnable tasks frequent opportunities to execute, but context switching adds overhead and can disturb caches. Long slices may improve efficiency for sustained work while making interactive tasks wait longer. The actual policy also considers priorities and fairness. I would evaluate response latency and throughput for the target workload rather than assume one time slice works everywhere. Tasks waiting for I/O need not consume their full slice.
What interviewers listen for- Balance responsiveness and overhead
- Consider cache and switching costs
- Account for priorities and fairness
- Measure latency and throughput
Likely follow-up: How would an interactive workload differ from a batch workload?
7.Why should a condition-variable wait normally check its predicate in a loop?hard
A condition variable is used with shared state protected by a mutex. Waiting atomically releases the mutex and blocks, then reacquires it before returning. A wakeup does not guarantee the desired predicate is true: another thread may have consumed the resource, and some APIs permit spurious wakeups. Check the predicate again while holding the mutex and wait if necessary. The shared predicate, rather than the notification itself, determines whether proceeding is safe.
What interviewers listen for- Protect the predicate with a mutex
- Waiting releases and reacquires the lock
- Wakeups do not guarantee the condition
- Recheck in a loop
Likely follow-up: How can checking the predicate outside the lock lose a notification?
8.Why should files and sockets be closed explicitly?mid
Files and sockets hold operating-system resources that are finite, even when the language manages object memory automatically. Relying on garbage collection can delay cleanup and exhaust descriptors or connections. Use the language’s structured cleanup mechanism so normal returns and exceptions both release the resource. Make ownership clear when a resource is shared. I would monitor descriptor counts and connection pools when a service fails only after running for a long time.
What interviewers listen for- OS resources are finite
- Memory collection may not release resources promptly
- Use structured cleanup on error paths
- Clarify ownership and monitor resource counts
Likely follow-up: What symptoms would you expect from a file-descriptor leak?
No questions match that filter.
Prefer multiple choice? All 11 Operating Systems MCQs with answers →