Operating Systems Interview Questions

The OS questions software engineering interviews ask most, with model answers and the follow-ups to expect.

Est. 40 min Updated Suggest a fix
// Part 01 — How to answer

Define, Contrast, Then Give an Example

Strong OS interview answers make assumptions explicit and distinguish similar concepts. Start with a short definition, contrast the nearest alternative, and illustrate with a state transition or workload. For numerical questions, show the formula and intermediate values rather than stating only a final number. The questions below are representative fundamentals for GATE and placement preparation, not a prediction of any specific interview.

🎯 Pro Tip
When asked a broad question, check whether the interviewer means theory, a particular OS interface, or practical Linux behavior. State which model you are using.
// Part 02 — Processes

Questions 1–5: Execution and Sharing

1. What is the difference between a program and a process? A program is passive code/data; a process is an executing instance with an address space, state, and OS-managed resources. Multiple processes can run the same executable independently.

2. What is a PCB? The process-control-block abstraction is kernel metadata needed to manage and resume a process: state, saved context, scheduling data, address-space information, and resource references. Implementations may spread it across structures.

3. What is the difference between a process and a thread? Processes typically have separate address spaces and stronger isolation. Threads share selected process resources and memory but have individual stacks, registers, and scheduling state. Shared state makes thread communication efficient but requires synchronization.

4. What do fork and exec do? On POSIX, fork creates a child with a copy-like view of the parent; copy-on-write can defer physical copying. Exec replaces the calling process's program image. A shell commonly forks and then execs a command.

5. What is a context switch? The OS saves enough execution state for one task to resume and restores another's. It enables multiplexing but consumes time and can disturb caches; it is not application progress itself.

// Part 03 — Scheduling

Questions 6–9: Policies and Metrics

6. Preemptive versus non-preemptive scheduling? A preemptive policy can take the CPU from a running task, often on a timer or higher-priority arrival. A non-preemptive task keeps it until it blocks or finishes. Preemption improves responsiveness but adds coordination and switching overhead.

7. Why can FCFS perform poorly for interactive work? A short job behind a long CPU burst waits—the convoy effect. FCFS is simple and fair by arrival order, but that is not the same as low response time.

8. What is the difference between SJF and SRTF? SJF selects the shortest next CPU burst without preemption; shortest-remaining-time-first can preempt when a job with less remaining time arrives. Exact burst knowledge is usually unavailable, so practical policies estimate behavior.

9. How do you calculate turnaround and waiting time? TAT = completion − arrival. If CPU burst is the only service and other wait is not counted, WT = TAT − burst. Response time is first CPU start minus arrival. Include the workload and assumptions in the answer.

A small FCFS/SJF exercise; assume one CPU, zero switching cost, and ties by arrival.
JobArrivalBurst
P104
P212
P321

Under FCFS, chart 0 | P1 | 4 | P2 | 6 | P3 | 7, so WT is 0, 3, 4 and average 7/3. Non-preemptive SJF has only P1 available at time 0; then P3, then P2: 0 | P1 | 4 | P3 | 5 | P2 | 7, WT 0, 2, 4 and average 2. These values assume no preemption after P1 starts.

// Part 04 — Concurrency

Questions 10–13: Locks and Deadlocks

10. What is a race condition? A result depends on uncontrolled timing/interleaving of concurrent operations. Protect shared invariants with synchronization; sleeping or repeating the test does not make the code safe.

11. Mutex versus semaphore? A mutex represents exclusive ownership of a critical section. A semaphore represents a count of available permits or events; a counting semaphore is useful for a resource pool. The distinction matters for ownership and signaling semantics.

mutex_answer.c
c
#include <pthread.h>
#include <stdio.h>

static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static int completed = 0;

static void *work(void *unused) {
    (void)unused;
    pthread_mutex_lock(&lock);
    ++completed; /* protected invariant: count updates are serialized */
    pthread_mutex_unlock(&lock);
    return NULL;
}

int main(void) {
    pthread_t a, b;
    if (pthread_create(&a, NULL, work, NULL) != 0) return 1;
    if (pthread_create(&b, NULL, work, NULL) != 0) return 1;
    pthread_join(a, NULL);
    pthread_join(b, NULL);
    printf("completed=%d
", completed);
    pthread_mutex_destroy(&lock);
    return 0;
}

This is an interview-sized illustration; robust application code should join already-created threads and release resources on every error path.

12. Name the Coffman deadlock conditions. Mutual exclusion, hold-and-wait, no preemption, and circular wait. All four must hold in the classic model. Prevention breaks at least one; a global lock order, for example, prevents circular wait if obeyed consistently.

13. Deadlock, starvation, and livelock? Deadlock is a circular wait with no progress; starvation is indefinite postponement while other work may proceed; livelock is activity without useful progress. Solutions differ: a timeout can reveal a wait but does not itself make recovery safe.

📌 Real World Example
If A holds L1 and waits for L2 while B holds L2 and waits for L1, draw A → B → A. Then identify the lock-order rule that removes the cycle.
// Part 05 — Memory

Questions 14–16: Paging and Faults

14. What does the MMU do? It translates virtual addresses and checks permissions using OS-managed mappings, often accelerated by a TLB. It is hardware that participates in memory protection and translation.

15. What is a page fault? An exception on an access needing OS handling, such as a legal page not currently resident, copy-on-write, or an invalid/protected access. The OS may resolve it and resume, or report a failure. Not every page fault means a crash.

16. Compare FIFO, LRU, and Optimal replacement. FIFO evicts the earliest-loaded page; LRU evicts the least recently used; Optimal evicts the page used farthest in the future and is therefore an offline benchmark. On reference string 1,2,3,1,4,2,5,1,2,3,4,5 with three empty frames, counts are FIFO=10, LRU=10, Optimal=7. A page-fault count depends on frame count and initial assumptions.

faults.py
python
def lru_faults(references, capacity):
    frames = []
    faults = 0
    for page in references:
        if page in frames:
            frames.remove(page)  # move recently used page to the newest end
            frames.append(page)
        else:
            faults += 1
            if len(frames) == capacity:
                frames.pop(0)
            frames.append(page)
    return faults

refs = [1, 2, 3, 1, 4, 2, 5, 1, 2, 3, 4, 5]
print(lru_faults(refs, 3))
// Part 06 — Storage and practice

Questions 17–18: Files, Durability, and Follow-Ups

17. What is an inode? In Unix-like filesystems, it is metadata and data-block reference information for a filesystem object. Directory entries associate names with objects; a filename is not usually stored as the inode's defining identity.

18. What is journaling, and does it guarantee durability? Journaling records filesystem changes to help recover a consistent structure after a crash. It does not necessarily journal all file data or guarantee that every successful buffered write is on persistent media. Durability requires the right sync/ordering contract for the filesystem and device.

Likely follow-ups: What assumptions did you make about arrivals or frame count? How do you avoid starvation? What happens on a spurious wakeup? How would you measure page faults? Which layer buffers the write? Give a counterexample to a claim that sounds universal.

bash
# Quick practical review on Linux
ps -eo pid,ppid,stat,comm | head
free -h
vmstat 1 3
stat .

These commands complement theory but do not expose every internal policy. In an interview, explain which measurement you would collect next and why.

  1. Define the OS abstraction precisely.
  2. State assumptions and draw a small example or calculation.
  3. Compare with the closest related concept.
  4. Mention one trade-off, failure mode, or platform caveat.
// Part 07 — Pitfalls

Answer with Precision

Giving a memorized slogan without assumptions

Why: A scheduling or replacement answer changes with the workload and model.

Fix: State arrivals, frame count, preemption, and tie-breaking before calculating.

Confusing two neighboring concepts

Why: Similar terms describe different layers or guarantees.

Fix: Define each concept and provide one contrast before adding detail.

Treating an observation as a universal guarantee

Why: A command samples one system at one moment.

Fix: Describe the observation limits and what additional evidence is needed.

Ignoring trade-offs and failure modes

Why: An idealized definition omits the engineering constraints.

Fix: Name one cost, edge case, or recovery path for every mechanism.

// Part 08 — Practice

Apply It to a Small System

Practice

Trace, calculate, and explain

  1. Draw the state, resource, or address transitions for a realistic workload, including a wait or failure path.
  2. Run a relevant Linux observation command from this lesson and explain what it can and cannot prove.
  3. Implement the small C or Python exercise, change one input, and predict the result before executing it.
  4. Explain one design choice with a precise invariant, a concrete example, and a trade-off.

Hint: Write assumptions first, then use a trace or calculation to support your explanation.

🎯 Key Takeaways

  • ✓Interview answers are strongest when they define, contrast, state assumptions, and give a concrete example.
  • ✓Processes isolate address spaces; threads share selected resources and need synchronization around shared state.
  • ✓Scheduling metrics must be calculated from an explicit arrival/burst trace and policy assumptions.
  • ✓Mutexes, semaphores, and deadlock conditions describe different coordination concerns.
  • ✓Page faults can be recoverable; replacement counts depend on the reference string and frame assumptions.
  • ✓Filesystem journaling supports recovery but does not automatically guarantee application-data durability.

Next

What comes next

You have completed Operating Systems. Continue with data structures and algorithms to strengthen your problem-solving foundations.

Next course · Data Structures & Algorithms →

HELP US IMPROVE

How was this lesson?

Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.

Choose your feedback

Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.

Share

Discussion

0

Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.

Continue with GitHub
Loading...