Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials
Operating System

Top 50 Operating System Interview Questions

Curated questions covering processes, threads, scheduling, deadlocks, memory management, virtual memory, file systems, and synchronization.

01

What is the difference between a process and a thread?

  • Process - independent program in execution. Has its own memory space, file handles, and resources. Heavyweight.
  • Thread - lightweight unit of execution within a process. Shares memory and resources with other threads in the same process.
  • Context switch between processes is more expensive than between threads.
02

What is a context switch?

A context switch is the OS saving the state (PCB) of the current process/thread and loading the state of the next one. Overhead includes saving/restoring registers, program counter, and memory maps. Frequent context switches reduce CPU efficiency.

03

What are the CPU scheduling algorithms?

  • FCFS (First Come First Served) - non-preemptive. Simple. Convoy effect.
  • SJF (Shortest Job First) - optimal average waiting time. Can cause starvation.
  • Round Robin - preemptive. Each process gets a time quantum. Fair. Good for time-sharing.
  • Priority Scheduling - highest priority runs first. Can cause starvation; solved by aging.
  • MLFQ (Multi-Level Feedback Queue) - combines multiple queues with different priorities.
04

What are the four necessary conditions for a deadlock?

  • Mutual Exclusion - at least one resource is non-shareable.
  • Hold and Wait - a process holds resources while waiting for more.
  • No Preemption - resources cannot be forcibly taken from a process.
  • Circular Wait - a circular chain of processes each waiting for a resource held by the next.
  • All four must hold simultaneously for a deadlock to occur.
05

What is the difference between deadlock prevention, avoidance, and detection?

  • Prevention - eliminate one of the four necessary conditions. Simple but restrictive.
  • Avoidance - use algorithms like Banker's Algorithm to ensure system never enters unsafe state.
  • Detection - allow deadlocks to occur, detect them, and recover by killing processes or preempting resources.
06

What is the difference between paging and segmentation?

  • Paging - divides memory into fixed-size pages. No external fragmentation. Internal fragmentation possible.
  • Segmentation - divides memory into variable-size segments (code, data, stack). No internal fragmentation. External fragmentation possible.
  • Modern OS use segmentation with paging combined.
07

What is virtual memory?

Virtual memory allows processes to use more memory than physically available by storing parts of the address space on disk (swap space). The OS uses demand paging to load pages only when needed. Provides memory isolation between processes.

08

What is a page fault?

A page fault occurs when a process accesses a page not currently in physical memory. The OS must load the page from disk (swap space) into a free frame. Types: minor (page in memory but not mapped) and major (page must be read from disk).

09

What is thrashing?

Thrashing occurs when a process spends more time swapping pages in and out than executing. Caused by insufficient physical memory. Solution: reduce degree of multiprogramming, use working set model, or add more RAM.

10

What are the page replacement algorithms?

  • FIFO - replaces the oldest page. Simple. Suffers from Belady's anomaly.
  • LRU (Least Recently Used) - replaces the page not used for the longest time. Good performance. Expensive to implement exactly.
  • Optimal - replaces the page not used for the longest time in the future. Theoretical best. Not implementable.
  • Clock (Second Chance) - approximates LRU using a reference bit. Practical.
11

What is the difference between internal and external fragmentation?

  • Internal fragmentation - wasted space inside an allocated block (e.g., paging allocates 4KB but process needs 3KB).
  • External fragmentation - free memory exists but is scattered in small non-contiguous blocks (e.g., segmentation).
  • Compaction can reduce external fragmentation but is expensive.
12

What is a semaphore?

A semaphore is a synchronization primitive with an integer value. Operations: wait (P) decrements value; if negative, blocks. signal (V) increments value; wakes a blocked process. Binary semaphore (0/1) acts like a mutex. Counting semaphore allows N concurrent accesses.

Example
// Semaphore usage (pseudocode)
semaphore mutex = 1;
wait(mutex);   // P operation - enter critical section
// critical section
signal(mutex); // V operation - exit critical section
13

What is the difference between a mutex and a semaphore?

  • Mutex - ownership-based lock. Only the thread that locked it can unlock it. Used for mutual exclusion.
  • Semaphore - signaling mechanism. Any thread can signal. Can be used for both mutual exclusion and synchronization.
  • Binary semaphore is similar to mutex but lacks ownership semantics.
14

What is the critical section problem?

  • Critical section - code segment accessing shared resources. Must not be executed by more than one process simultaneously.
  • Requirements: Mutual Exclusion, Progress (if no process in CS, one waiting should enter), Bounded Waiting (limit on how long a process waits).
  • Solutions: Peterson's algorithm, semaphores, monitors, hardware instructions (test-and-set).
15

What is the producer-consumer problem?

The producer-consumer (bounded buffer) problem: producers add items to a shared buffer, consumers remove them. Requires synchronization to prevent overflow, underflow, and race conditions. Solved with semaphores: empty, full, and mutex.

Example
// Pseudocode
semaphore empty = N, full = 0, mutex = 1;
// Producer
wait(empty); wait(mutex);
add_item();
signal(mutex); signal(full);
// Consumer
wait(full); wait(mutex);
remove_item();
signal(mutex); signal(empty);
16

What is the difference between preemptive and non-preemptive scheduling?

  • Non-preemptive - once a process gets CPU, it runs until it voluntarily yields or terminates. Simple. Can cause starvation.
  • Preemptive - OS can interrupt a running process and give CPU to another. Better responsiveness. More complex. Used in modern OS.
17

What is a system call?

A system call is the interface between a user program and the OS kernel. Allows user-mode programs to request kernel services (file I/O, process creation, memory allocation). Examples: read(), write(), fork(), exec(), open(), close().

18

What is the difference between user mode and kernel mode?

  • User mode - restricted mode. Cannot directly access hardware or kernel memory. Most application code runs here.
  • Kernel mode - privileged mode. Full access to hardware and memory. OS kernel runs here.
  • Mode switch occurs on system calls, interrupts, and exceptions.
19

What is a file system?

A file system organizes and stores files on storage devices. Manages file metadata (name, size, permissions, timestamps), directory structure, and free space. Examples: ext4 (Linux), NTFS (Windows), APFS (macOS), FAT32.

20

What is an inode?

An inode (index node) is a data structure in Unix file systems storing file metadata: permissions, owner, size, timestamps, and pointers to data blocks. Does NOT store the filename. Directory entries map filenames to inode numbers.

21

What is the difference between a hard link and a soft link?

  • Hard link - another directory entry pointing to the same inode. File data persists until all hard links are deleted. Cannot span file systems.
  • Soft link (symbolic link) - a file containing a path to another file. Can span file systems. Breaks if target is deleted.
Example
ln file.txt hardlink.txt      # hard link
ln -s file.txt softlink.txt   # soft link (symlink)
22

What is spooling?

Spooling (Simultaneous Peripheral Operations On-Line) stores data in a buffer (spool) for a device that cannot accept interleaved data streams. Classic example: print spooler queues print jobs so multiple processes can send print requests without waiting.

23

What is the difference between multiprogramming, multitasking, and multiprocessing?

  • Multiprogramming - multiple programs loaded in memory. CPU switches when one does I/O. Maximizes CPU utilization.
  • Multitasking - multiple tasks share CPU via time-slicing. Gives illusion of parallelism on single CPU.
  • Multiprocessing - multiple CPUs execute processes truly in parallel.
24

What is Belady's anomaly?

Belady's anomaly is the counterintuitive phenomenon where increasing the number of page frames causes more page faults with FIFO page replacement. Does not occur with LRU or Optimal algorithms. LRU and Optimal are stack algorithms, immune to Belady's anomaly.

25

What is the difference between monolithic kernel and microkernel?

  • Monolithic kernel - entire OS runs in kernel space. Fast (no context switches for services). Hard to maintain. Examples: Linux, Unix.
  • Microkernel - minimal kernel; services (file system, drivers) run in user space. More stable and secure. Slower due to IPC overhead. Examples: Mach, QNX.
26

What is the difference between a process and a program?

  • Program - passive entity. A file on disk containing instructions.
  • Process - active entity. A program in execution with its own memory, registers, and state.
  • One program can create multiple processes (e.g., running the same executable twice).
27

What is the difference between fork() and exec()?

  • fork() - creates a new child process as a copy of the parent. Both parent and child continue from the fork() call.
  • exec() - replaces the current process image with a new program. Does not create a new process.
  • Typical pattern: fork() then exec() in child to run a new program.
Example
pid_t pid = fork();
if (pid == 0) {
    // child process
    execl("/bin/ls", "ls", "-l", NULL);
} else {
    // parent process
    wait(NULL);
}
28

What is the difference between a zombie process and an orphan process?

  • Zombie process - process has finished but its entry remains in the process table because the parent has not called wait(). Wastes process table entries.
  • Orphan process - parent has terminated before the child. The child is adopted by init (PID 1) which calls wait() for it.
29

What is the difference between a binary semaphore and a mutex?

  • Binary semaphore - value is 0 or 1. Any thread can signal it. No ownership.
  • Mutex - has ownership. Only the thread that locked it can unlock it. Prevents priority inversion with priority inheritance.
  • Use mutex for mutual exclusion; binary semaphore for signaling.
30

What is the difference between a monitor and a semaphore?

  • Semaphore - low-level primitive. Programmer must carefully place wait/signal calls. Error-prone.
  • Monitor - high-level synchronization construct. Mutual exclusion is automatic. Uses condition variables (wait, signal). Easier to use correctly.
31

What is the difference between demand paging and pre-paging?

  • Demand paging - pages loaded only when accessed (on page fault). Less memory used initially. More page faults at startup.
  • Pre-paging - loads pages before they are needed (predicted). Fewer page faults. May waste memory loading unneeded pages.
32

What is a real-time operating system (RTOS)?

  • Hard real-time - deadlines must be met absolutely. Missing a deadline is a system failure. Examples: aircraft control, pacemakers.
  • Soft real-time - deadlines are important but occasional misses are tolerable. Examples: video streaming, online gaming.
  • RTOS provides deterministic scheduling (e.g., Rate Monotonic, EDF).
33

What is the difference between cooperative and preemptive multitasking?

  • Cooperative - processes voluntarily yield CPU. If a process does not yield, it can monopolize CPU. Used in early Windows (3.x), macOS (classic).
  • Preemptive - OS forcibly interrupts processes after time quantum expires. Fairer. Used in modern OS.
34

What is a Translation Lookaside Buffer (TLB)?

The TLB is a hardware cache that stores recent virtual-to-physical address translations. Speeds up memory access by avoiding page table lookups. TLB hit: O(1) translation. TLB miss: must walk page table. TLB is flushed on context switch.

35

What is the difference between PCB and TCB?

  • PCB (Process Control Block) - data structure storing process state: PID, program counter, registers, memory maps, open files, scheduling info.
  • TCB (Thread Control Block) - stores thread-specific state: thread ID, program counter, registers, stack pointer. Shares process resources.
36

What is the difference between logical and physical address?

  • Logical address (virtual address) - generated by CPU. Used by programs. Starts from 0 for each process.
  • Physical address - actual location in RAM. Translated from logical address by MMU using page tables.
  • Memory Management Unit (MMU) performs the translation.
37

What is the difference between blocking and non-blocking I/O?

  • Blocking I/O - process waits until I/O completes. Simple but wastes CPU.
  • Non-blocking I/O - process continues execution; checks later or gets notified. More complex but efficient.
  • Asynchronous I/O - OS notifies process when I/O completes via callback or signal.
38

What is the difference between kernel thread and user thread?

  • Kernel thread - managed by OS. OS is aware of each thread. True parallelism on multi-core. Context switch is expensive.
  • User thread - managed by user-space library. OS sees only one process. Fast context switch. Cannot run truly in parallel.
  • Modern systems use hybrid (M:N) model.
39

What is a file descriptor?

A file descriptor is a non-negative integer that uniquely identifies an open file within a process. Standard descriptors: 0 (stdin), 1 (stdout), 2 (stderr). Created by open(), socket(), pipe(). Closed with close().

40

What is the difference between a pipe and a socket?

  • Pipe - unidirectional IPC between related processes (parent-child). Anonymous pipe: temporary. Named pipe (FIFO): persistent, between unrelated processes.
  • Socket - bidirectional IPC. Can communicate between processes on different machines over a network. More flexible.
Example
int fd[2];
pipe(fd);  // fd[0] = read end, fd[1] = write end
write(fd[1], "hello", 5);
read(fd[0], buf, 5);
41

What is the difference between a spinlock and a mutex?

  • Spinlock - busy-waits (loops) until lock is available. No context switch. Efficient for very short critical sections on multi-core.
  • Mutex - puts thread to sleep if lock unavailable. Context switch overhead. Better for longer critical sections.
42

What is a page table?

A page table maps virtual page numbers to physical frame numbers. Each process has its own page table. Multi-level page tables (2-level, 4-level in x86-64) reduce memory overhead. Inverted page table uses one entry per physical frame.

43

What is the working set model?

The working set model tracks the set of pages a process actively uses in a time window (working set window). If a process's working set fits in memory, it runs efficiently. If not, thrashing occurs. Used to determine how many frames to allocate to each process.

44

What are memory-mapped files?

Memory-mapped files map a file or device into the process's virtual address space. Allows file I/O using memory operations (read/write to pointers). Used for: shared memory between processes, loading executables, and large file processing.

Example
// mmap example (C)
int fd = open("file.txt", O_RDONLY);
char *data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
// access data[i] directly
munmap(data, size);
45

What is DMA (Direct Memory Access)?

DMA allows hardware devices to transfer data directly to/from memory without CPU involvement. The CPU initiates the transfer, then the DMA controller handles it. CPU is free to do other work. Used for disk I/O, network cards, and audio.

46

What is the difference between an interrupt and a trap?

  • Interrupt - asynchronous signal from hardware (keyboard, timer, disk). Causes CPU to stop current task and run interrupt handler.
  • Trap (software interrupt) - synchronous event caused by program (system call, division by zero, page fault). Transfers control to OS.
47

What is a race condition?

A race condition occurs when the outcome of a program depends on the relative timing of events (e.g., two threads reading and writing shared data without synchronization). Result is non-deterministic and can cause data corruption.

Example
// Race condition example
int counter = 0;
// Thread 1: counter++  (read, increment, write)
// Thread 2: counter++  (read, increment, write)
// Final value may be 1 instead of 2 if interleaved
48

What is priority inversion?

Priority inversion occurs when a high-priority task is blocked waiting for a resource held by a low-priority task, while a medium-priority task preempts the low-priority task. Solution: priority inheritance (low-priority task temporarily inherits high-priority task's priority).

49

What is the Banker's Algorithm?

The Banker's Algorithm is a deadlock avoidance algorithm. Before granting a resource request, it checks if the resulting state is safe (all processes can eventually complete). If safe, grant; otherwise, make the process wait. Requires knowing maximum resource needs in advance.

50

What is the difference between hard real-time and soft real-time systems?

  • Hard real-time - missing a deadline causes system failure. Used in safety-critical systems: aircraft autopilot, pacemakers, anti-lock brakes.
  • Soft real-time - deadlines are important but occasional misses are acceptable. Used in multimedia, gaming, and video conferencing.
  • RTOS schedulers (Rate Monotonic, EDF) guarantee hard real-time deadlines.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.