Operating System Interview Questions for Freshers (with Solved Examples)

Top operating system interview questions for freshers with clear answers: process vs thread, CPU scheduling, deadlock, semaphores, paging, virtual memory and page replacement, with solved numerical examples.

Why OS Questions Matter in Technical Interviews

Operating systems is the third core subject in fresher technical interviews, alongside OOPs and DBMS. Interviewers at TCS, Infosys, Wipro, Accenture, Cognizant and product companies regularly ask about processes, threads, scheduling, deadlocks and memory.

Two kinds of questions come up. Most are short theory questions, such as "What is the difference between a process and a thread?" Some are small numerical problems, such as calculating average waiting time or counting page faults. Freshers often skip the numerical side, which is a mistake, because these questions also appear in technical MCQs.

This guide covers the most frequently asked theory questions with short answers, then works through CPU scheduling and page replacement examples step by step, with small Python programs you can use to check your own answers.

Basic OS Interview Questions

Q1. What is an operating system, and what does it do?

An operating system is software that manages a computer's hardware and provides services to programs. Its main jobs are process management, memory management, file management, device management, and security. Windows, Linux, macOS and Android are examples.

Q2. What is a kernel? What is the difference between a monolithic kernel and a microkernel?

The kernel is the core part of the OS that runs with full access to the hardware. A monolithic kernel runs most OS services, such as file systems and drivers, inside the kernel, which is fast but means one bug can crash the whole system. Linux uses this design. A microkernel keeps only the essentials in the kernel and runs other services separately, which is more stable but adds communication overhead.

Q3. What is the difference between a program and a process?

A program is a passive file of instructions stored on disk. A process is a program in execution, with its own memory, registers and state. Opening the same program twice creates two separate processes.

Q4. What is the difference between a process and a thread?

One of the most asked OS questions:

PointProcessThread
DefinitionAn independent program in executionA unit of execution inside a process
MemoryHas its own separate memory spaceShares the memory of its process
Creation costHeavy and slowerLight and faster
CommunicationNeeds inter-process communication (pipes, sockets)Direct, through shared memory
If one crashesOther processes are usually unaffectedCan bring down the whole process
ExampleTwo separate browser windows as separate processesOne tab loading images while you scroll

Q5. What are the states of a process?

A process moves through five main states: New (being created), Ready (waiting for the CPU), Running (executing on the CPU), Waiting or Blocked (waiting for input/output or an event), and Terminated (finished). Information about each process, such as its state, registers and memory details, is kept in a Process Control Block (PCB).

Q6. What is a context switch?

A context switch is when the CPU saves the state of the running process into its PCB and loads the state of another process. It lets many processes share one CPU, but it is pure overhead, because no useful work is done during the switch.

Q7. What is the difference between multiprogramming, multitasking, multithreading and multiprocessing?

These four terms sound similar but mean different things:

TermMeaning
MultiprogrammingSeveral programs kept in memory so the CPU always has something to run
MultitaskingThe CPU switches between tasks quickly so they appear to run at the same time
MultithreadingOne process runs several threads at the same time
MultiprocessingA system with two or more CPUs or cores running work truly in parallel

Q8. What is a system call?

A system call is how a program asks the OS for a service it cannot do directly, such as reading a file, creating a process or sending data over the network. Examples in Linux include open(), read(), write() and fork().

CPU Scheduling

The scheduler decides which ready process gets the CPU next. In non-preemptive scheduling, a process keeps the CPU until it finishes or waits. In preemptive scheduling, the OS can take the CPU away, for example when a time slice ends.

AlgorithmHow it worksMain drawback
FCFS (First Come First Served)Runs processes in order of arrivalShort jobs wait behind long ones (convoy effect)
SJF (Shortest Job First)Runs the shortest burst firstLong jobs can starve; burst time must be known
SRTF (Shortest Remaining Time First)Preemptive SJFFrequent switching, starvation possible
PriorityRuns the highest-priority process firstLow-priority starvation, fixed by aging
Round RobinEach process gets a fixed time slice in turnToo small a slice causes heavy switching overhead

Key Formulas

Turnaround time = Completion time − Arrival time
Waiting time = Turnaround time − Burst time

Worked Example: FCFS vs SJF

Four processes arrive as follows (times in milliseconds):

ProcessArrival timeBurst time
P105
P213
P328
P436

FCFS: the order is P1 (0–5), P2 (5–8), P3 (8–16), P4 (16–22). Turnaround times are 5, 7, 14 and 19, so the average turnaround time is 11.25 ms. Waiting times are 0, 4, 6 and 13, so the average waiting time is 5.75 ms.

SJF (non-preemptive): only P1 has arrived at time 0, so it runs from 0 to 5. At time 5, the shortest waiting job is P2 (3), then P4 (6), then P3 (8). The order is P1 (0–5), P2 (5–8), P4 (8–14), P3 (14–22). Average turnaround is 10.75 ms and average waiting time is 5.25 ms, better than FCFS because the short jobs no longer wait behind P3.

Use these two functions to check your answers to any FCFS or SJF question:

Python
def fcfs(processes):                 # list of (name, arrival, burst)
    time, result = 0, []
    for name, arrival, burst in sorted(processes, key=lambda p: p[1]):
        time = max(time, arrival) + burst  # wait if the CPU is idle
        tat = time - arrival               # turnaround = completion - arrival
        result.append((name, tat, tat - burst))   # waiting = turnaround - burst
    return result
Python
def sjf(processes):                  # non-preemptive shortest job first
    pending = sorted(processes, key=lambda p: p[1])
    time, result = 0, []
    while pending:
        ready = [p for p in pending if p[1] <= time] or [pending[0]]
        name, arrival, burst = min(ready, key=lambda p: (p[2], p[1]))
        pending.remove((name, arrival, burst))
        time = max(time, arrival) + burst
        tat = time - arrival
        result.append((name, tat, tat - burst))
    return result

Each function returns (process, turnaround time, waiting time) in the order the processes run. For Round Robin, the same idea applies with a queue: run each process for one time slice, then move it to the back. See our Stack and Queue Interview Questions guide for how queues work.

Process Synchronization and Deadlock

Q9. What is a race condition, and what is a critical section?

A race condition happens when two threads update shared data at the same time and the result depends on timing. For example, two threads adding 1 to a counter can both read 5 and both write 6. The critical section is the part of code that touches shared data, and only one thread should run it at a time.

Q10. What is the difference between a mutex and a semaphore?

Both control access to shared resources, but they work differently:

PointMutexSemaphore
What it isA lock with two states: locked or unlockedAn integer counter with wait() and signal() operations
How many can enterOnly one thread at a timeUp to the counter's value (counting semaphore)
OwnershipOnly the thread that locked it should unlock itAny thread can signal
Typical useProtecting a critical sectionControlling access to a pool of resources, such as 3 printers

Q11. What is a deadlock? What are its four necessary conditions?

A deadlock is when a set of processes wait forever, each holding a resource another one needs. It can only happen if all four conditions hold together: mutual exclusion (a resource can be used by only one process), hold and wait (a process holds one resource while waiting for another), no preemption (resources cannot be taken away), and circular wait (P1 waits for P2, P2 waits for P1). Breaking any one condition prevents deadlock.

Q12. How does an OS handle deadlocks?

Four approaches: prevention (design the system so one of the four conditions can never hold, such as requesting all resources at once), avoidance (check each request and grant it only if the system stays in a safe state, as in the Banker's algorithm), detection and recovery (allow deadlocks, detect them and then kill or roll back a process), and ignoring the problem, which many general-purpose systems do because deadlocks are rare.

Q13. What is the difference between deadlock and starvation?

In a deadlock, processes are stuck waiting for each other and none can proceed. In starvation, a process waits indefinitely because others keep getting priority, even though the system is still making progress. Aging, which gradually raises the priority of waiting processes, is a common fix for starvation.

Memory Management

Q14. What is the difference between paging and segmentation?

Paging divides memory into fixed-size blocks: pages in logical memory and frames in physical memory. It avoids external fragmentation. Segmentation divides a program into variable-size logical parts, such as code, stack and data, which matches how programmers think but can cause external fragmentation.

Q15. What is internal vs external fragmentation?

Internal fragmentation is wasted space inside an allocated block, such as a 4 KB page holding only 3 KB of data. External fragmentation is free memory split into small gaps between allocations, so a large request fails even though the total free memory is enough.

Q16. What is virtual memory, and what is a page fault?

Virtual memory lets a process use more memory than is physically available by keeping some pages on disk and loading them only when needed. A page fault happens when a process accesses a page that is not currently in RAM, so the OS must load it from disk.

Q17. What is thrashing?

Thrashing is when the system spends more time swapping pages in and out of memory than doing useful work. It happens when too many processes compete for too little memory, and it makes the system extremely slow.

Page Replacement: Worked Example

When memory is full and a page fault occurs, the OS must remove a page. The three algorithms interviewers ask about are FIFO (remove the page loaded earliest), LRU (remove the page not used for the longest time) and Optimal (remove the page that will not be used for the longest time in the future; ideal but impossible to implement in practice).

Reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 3 frames.

AlgorithmPage faults
FIFO15
LRU12
Optimal9

Optimal always gives the fewest faults, which makes it a benchmark for comparing other algorithms. Use this function to count FIFO and LRU faults for any reference string:

Python
def page_faults(refs, frames, policy="FIFO"):
    memory, faults = [], 0
    for page in refs:
        if page in memory:
            if policy == "LRU":            # mark as most recently used
                memory.remove(page)
                memory.append(page)
            continue
        faults += 1
        if len(memory) == frames:
            memory.pop(0)                  # FIFO: oldest loaded; LRU: least recently used
        memory.append(page)
    return faults

Belady's Anomaly

You would expect more frames to mean fewer page faults, but FIFO can break this rule. For the reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5, FIFO gives 9 faults with 3 frames but 10 faults with 4 frames. This is Belady's anomaly. LRU and Optimal never show it: on the same string, LRU gives 10 faults with 3 frames and 8 with 4.

Common Mistakes Freshers Make

  • Saying threads have no memory of their own. Threads share the process's code, data and heap, but each thread has its own stack and registers.
  • Mixing up turnaround and waiting time. Turnaround is completion minus arrival; waiting is turnaround minus burst.
  • Listing only three deadlock conditions. Interviewers expect all four, and how breaking any one prevents deadlock.
  • Calling a mutex a "binary semaphore" with no difference. They behave similarly, but a mutex has ownership and a semaphore does not.
  • Skipping numerical practice. Scheduling and page-fault questions are common in technical MCQs. Practise a few by hand.

How to Prepare OS in One Week

  1. Day 1: OS basics, kernel types, process vs program, process states and PCB.
  2. Day 2: Process vs thread, context switching and system calls.
  3. Day 3: CPU scheduling. Solve 5 FCFS, SJF and Round Robin problems by hand, then check with the code above.
  4. Day 4: Race conditions, critical sections, mutex vs semaphore.
  5. Day 5: Deadlock conditions, handling methods and the Banker's algorithm idea.
  6. Day 6: Paging, segmentation, virtual memory and page replacement. Count faults for 3 reference strings.
  7. Day 7: Mock interview: answer 10 random questions from this page out loud in under a minute each.

OS is usually asked together with OOPs and DBMS questions, so revise all three before your technical round.

Frequently Asked Questions

What are the most important OS topics for fresher interviews?

Process vs thread, process states, CPU scheduling, deadlock and its four conditions, mutex vs semaphore, paging, virtual memory and page replacement.

What is the difference between a process and a thread?

A process is an independent program in execution with its own memory. A thread runs inside a process and shares its memory, which makes it lighter and faster to create.

What are the four conditions for deadlock?

Mutual exclusion, hold and wait, no preemption and circular wait. All four must hold at the same time for a deadlock to occur.

What is Belady's anomaly?

It is when increasing the number of frames increases the number of page faults. It can happen with FIFO page replacement but not with LRU or Optimal.

How do I calculate waiting time in CPU scheduling?

Waiting time = turnaround time − burst time, and turnaround time = completion time − arrival time. Average them across all processes.

Final Word

Operating system questions for freshers are about clear concepts and a few standard calculations. Learn the comparison tables, explain each answer with a simple example, and practise the scheduling and page-replacement problems until you can do them quickly.

For company-specific practice, see Accenture Interview Questions, TCS Interview Questions and Infosys Interview Questions.

Crack Your Placement with PlacementBaba

Free practice questions, mock tests and interview tipsStart Practicing — DSA Roadmap →