Operating System MCQ (Multiple Choice Questions and Answers)

41. What is the Least Recently Used (LRU) page replacement algorithm?

  1. An algorithm that replaces the page that has been used least frequently overall
  2. A page replacement algorithm that replaces the page that has not been used for the longest time — approximating the optimal algorithm by using past access history to predict future use
  3. An algorithm that replaces the page that was loaded into memory most recently
  4. A page replacement algorithm that removes pages in the order they were loaded (FIFO)

Answer : B
Explanation: LRU (Least Recently Used) replaces the page that has not been accessed for the longest time, based on the principle of temporal locality (recently used pages are likely to be used again). LRU performs close to the Optimal algorithm in practice and does not suffer from Belady’s anomaly. Implementation requires maintaining access timestamps or a stack. Hardware implementations use counters or stacks. Software approximations include: Reference bit (NRU), Aging algorithm, and Second-chance (Clock) algorithm. LRU is considered the best practical page replacement algorithm. Common page replacement algorithms: Optimal (OPT), LRU, FIFO, LFU, and Second-chance.

42. What is the critical section problem in operating systems?

  1. A problem that occurs when the OS crashes due to a critical hardware failure
  2. A problem of ensuring that when one process is executing in its critical section (code that accesses shared resources), no other process is allowed to execute in its critical section simultaneously
  3. A problem with allocating CPU time to the most critical processes in the system
  4. A security problem where unauthorized users access critical system files

Answer : B
Explanation: The critical section is a code segment that accesses shared resources (shared variables, files, hardware). The Critical Section Problem requires a solution satisfying three conditions: Mutual Exclusion (only one process in the critical section at a time), Progress (if no process is in the critical section, a waiting process must be able to enter in finite time), and Bounded Waiting (there is a limit on how many times other processes can enter before a waiting process gets its turn). Solutions include software solutions (Peterson’s Algorithm), hardware solutions (TestAndSet, Swap instructions), and OS-provided synchronization primitives (semaphores, mutexes, monitors).

43. What is a semaphore in operating systems?

  1. A hardware signal used to notify the CPU of an external interrupt
  2. An integer synchronization variable with two atomic operations — wait(P) and signal(V) — used to control access to shared resources and solve synchronization problems between processes
  3. A type of scheduling algorithm used for real-time operating systems
  4. A memory protection mechanism that prevents processes from accessing each other’s memory

Answer : B
Explanation: A Semaphore is an integer variable accessed only through two atomic operations: wait(S) [also called P or down]: if S > 0, decrement S; else block the calling process. signal(S) [also called V or up]: increment S; if any process is blocked, wake one up. Types: Binary Semaphore (value 0 or 1) — acts like a mutex for mutual exclusion. Counting Semaphore (any non-negative integer) — controls access to a resource with multiple instances. Semaphores solve classic synchronization problems: Producer-Consumer, Reader-Writer, Dining Philosophers. Limitation: semaphores can lead to deadlock if used incorrectly, and they do not prevent priority inversion.

44. What is a mutex (mutual exclusion lock) in operating systems?

  1. A memory allocation technique that ensures mutual access to RAM between processes
  2. A synchronization primitive that provides mutual exclusion — only one thread can hold the lock at a time, blocking all other threads attempting to acquire it until it is released
  3. A scheduling algorithm that mutually excludes low-priority processes from the CPU
  4. A type of file lock that prevents multiple users from editing a document simultaneously

Answer : B
Explanation: A Mutex (Mutual Exclusion Lock) is a synchronization object that allows only one thread to hold it at a time. Key operations: lock() (acquire) — if unlocked, the thread takes ownership and proceeds; if locked, the thread blocks until released. unlock() (release) — releases the mutex, allowing a waiting thread to proceed. Mutex vs Binary Semaphore: a mutex has ownership (only the locking thread can unlock it); a semaphore has no ownership concept. Mutexes prevent race conditions when multiple threads access shared data. They are the primary tool for thread synchronization in C (pthread_mutex) and modern programming languages.

45. What are the four necessary conditions for deadlock (Coffman’s conditions)?

  1. Starvation, Priority Inversion, Race Condition, and Livelock
  2. Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait — all four must simultaneously hold for deadlock to occur
  3. Multiprogramming, Resource Sharing, Process Blocking, and System Overload
  4. Resource Allocation, Process Scheduling, Memory Paging, and File Locking

Answer : B
Explanation: Coffman’s four necessary conditions for deadlock: (1) Mutual Exclusion — at least one resource must be held in a non-shareable mode (only one process can use the resource at a time). (2) Hold and Wait — a process holding at least one resource is waiting to acquire additional resources held by other processes. (3) No Preemption — resources cannot be forcibly taken away from a process; they must be released voluntarily. (4) Circular Wait — a circular chain of processes exists where each process holds a resource needed by the next. All four conditions must be present simultaneously for deadlock to occur. Eliminating any one prevents deadlock.

46. What are the different methods of handling deadlocks in an operating system?

  1. Kill all processes, restart the system, and reinstall the operating system
  2. Deadlock Prevention (eliminate at least one Coffman condition), Deadlock Avoidance (Banker’s algorithm), Deadlock Detection and Recovery, and Ignore the problem (Ostrich Algorithm)
  3. Use only single-resource allocation and avoid multi-resource programs entirely
  4. Deadlocks can only be handled by upgrading system hardware

Answer : B
Explanation: Four strategies for handling deadlock: Prevention — design the system to make at least one Coffman condition impossible (e.g., require processes to request all resources at once to prevent Hold-and-Wait). Avoidance — use resource allocation algorithms like the Banker’s Algorithm to ensure the system never enters an unsafe state. Detection and Recovery — allow deadlocks to occur, detect them using a Resource Allocation Graph or detection algorithm, then recover by preempting resources or terminating processes. Ostrich Algorithm (Ignore) — do nothing and hope deadlock is rare — used by most general-purpose OS like Windows and Linux because prevention/avoidance is too costly.

47. What is thrashing in an operating system?

  1. A technique used to improve CPU performance by executing multiple threads simultaneously
  2. A condition where a process spends more time swapping pages in and out of memory than actually executing, due to insufficient physical memory for its working set
  3. A disk scheduling problem where the read/write head thrashes between distant tracks
  4. A CPU overheating problem caused by running too many processes simultaneously

Answer : B
Explanation: Thrashing occurs when a process does not have enough frames (physical memory) to hold its working set — the set of pages actively being used. The process continuously generates page faults, swapping pages in and out so rapidly that actual execution barely progresses. CPU utilization drops sharply while disk I/O skyrockets. The OS may respond by adding more processes (thinking CPU is underutilized), making the situation worse. Solutions: Working Set Model (allocate enough frames for the working set), Page Fault Frequency (if too high, give more frames; if too low, take frames away), and reducing the degree of multiprogramming.

48. What is segmentation in memory management?

  1. A technique of dividing physical memory into equal-sized frames for allocation
  2. A memory management technique that divides a process’s logical address space into variable-sized segments (code, data, stack, heap) based on the logical program structure
  3. A method of segmenting a hard disk into multiple partitions for file storage
  4. A technique for dividing a process into multiple threads for parallel execution

Answer : B
Explanation: Segmentation divides a program’s address space into logical units called segments — each representing a meaningful program division like code segment, data segment, stack segment, and heap segment. Each segment has a name (or number) and a length. A segment table maps each segment number to its base address and limit in physical memory. Address translation: physical address = base[segment number] + offset (if offset < limit). Segmentation supports logical program structure and allows each segment to grow independently. Suffers from external fragmentation (variable-sized segments). Many modern systems combine paging and segmentation (segmented paging).

49. What is the difference between internal and external fragmentation?

  1. Internal fragmentation occurs outside RAM; external fragmentation occurs inside RAM
  2. Internal fragmentation is wasted space within allocated memory blocks; external fragmentation is wasted space between allocated blocks that is too small to satisfy any new request
  3. External fragmentation is caused by paging; internal fragmentation is caused by segmentation
  4. Both types of fragmentation refer to the same memory waste problem

Answer : B
Explanation: Internal Fragmentation occurs when memory allocated to a process is slightly larger than what the process needs — the leftover space inside the allocated block is wasted. Example: if a process needs 18KB but is allocated a 20KB block, 2KB is wasted internally. Paging suffers from internal fragmentation (last page may not be full). External Fragmentation occurs when total free memory is sufficient but it is scattered in small non-contiguous blocks that cannot satisfy a large memory request. Segmentation suffers from external fragmentation. Solution for external fragmentation: Compaction (reorganizing memory to combine free blocks) or using paging (which eliminates external fragmentation by using fixed-size frames).

50. What is the Translation Lookaside Buffer (TLB) in operating systems?

  1. A disk buffer that speeds up translation between file names and disk addresses
  2. A small, fast hardware cache inside the MMU that stores recent virtual-to-physical address translations to speed up memory access by avoiding page table lookups
  3. A software buffer that translates assembly language instructions to machine code
  4. A network buffer that translates logical addresses to physical network addresses

Answer : B
Explanation: The TLB (Translation Lookaside Buffer) is a hardware cache within the Memory Management Unit (MMU) that stores recently used page table entries (virtual page number → physical frame number mappings). When the CPU generates a virtual address: TLB Hit — the translation is found in TLB, no page table lookup needed (fast). TLB Miss — the page table in RAM is consulted, and the new translation is added to the TLB (slow). Effective Access Time (EAT) = hit ratio × TLB access time + miss ratio × (TLB + page table + memory) access time. TLB hit rates are typically 90-99% — dramatically speeding up virtual memory systems.