GATE CSE · subject-wise

GATE Operating System previous year questions

61 questions from GATE papers, newest first, each with the official answer and a worked explanation.

Practise Operating System with instant checking
GATE 2026 S1 · Q29MSQ1 mark · no negative· Easy

With respect to deadlocks in an operating system, which of the following statements is/are FALSE?

  1. (A)Banker's algorithm is used to prevent deadlocks
  2. (B)Deadlock formation can be prevented by ensuring that the hold and wait condition is not allowed
  3. (C)An assignment edge in a resource allocation graph is marked from a process to a resource
  4. (D)A safe state guarantees that all processes can finish without formation of a deadlock
Answer: A, C - show solution

(A) Banker's algorithm is deadlock avoidance (grants only requests that keep a safe state), not prevention: FALSE. (B) Denying hold-and-wait removes a necessary condition, which is prevention: true. (C) An assignment edge goes from a resource to a process; a request edge goes from process to resource: FALSE. (D) A safe state has a safe sequence in which all processes can finish: true. Answer: (A), (C).

Concept: Prevention breaks a Coffman condition; avoidance (Banker's) checks safety at run time. Edge direction in RAG: request P -> R, assignment R -> P.

GATE 2026 S1 · Q35NAT1 mark · no negative· Easy

Consider a system consisting of k instances of a resource R, being shared by 5 processes. Assume that each process requires a maximum of two instances of resource R and a process can request or release only one instance at a time. Further, a process can request the second instance of the resource only after acquiring the first instance. The minimum value of k for the system to be deadlock-free is ________. (answer in integer)

Answer: 6 - show solution

Worst case: every process holds one instance and waits for its second. With k = 5 all five hold one each and none can proceed: deadlock. With k = 6, after each holds one, one instance remains; some process gets its second, finishes and releases two, and the rest follow. Generally k ≥ Σ(maxᵢ - 1) + 1 = 5 × 1 + 1 = 6. Answer: 6.

Concept: Deadlock-freedom bound: give each process one less than its maximum, then add one. Answering 10 (everyone's full maximum) is the usual over-count.

GATE 2026 S1 · Q59NAT2 marks · no negative· Moderate

Consider a hard disk with a rotational speed of 15000 rpm. The time to move the read/write head from a track to its adjacent track is 1 millisecond. Initially, the head is on track 0. The number of sectors per track is 400. The sector size is 1024 bytes. It is necessary to transfer data from 10 randomly located sectors in each of the following tracks in the order: 5, 12 and 7. The total time for the data transfer (in milliseconds) from the hard disk is _________. (rounded off to one decimal place)

Answer: 77.3 - show solution

15000 rpm gives one rotation in 4 ms, so average rotational latency = 2 ms and transfer of one sector = 4/400 = 0.01 ms. Seek: track 0 → 5 = 5 ms, 5 → 12 = 7 ms, 12 → 7 = 5 ms, total 17 ms. Each of the 30 randomly located sectors costs an average latency plus its transfer: 30 × (2 + 0.01) = 60.3 ms. Total = 17 + 60.3 = 77.3 ms. Answer: 77.3.

Concept: Disk access = seek + rotational latency + transfer. Random sectors on the same track each pay half a rotation on average; sector size in bytes is a distractor.

GATE 2026 S1 · Q63NAT2 marks · no negative· Moderate

Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful in creating a process. The total number of times that the printf statement gets executed is ________. (answer in integer)

int main () {
    int i;
    for (i = 0; i < 3; i++){
        if (fork() == 0){
            continue;
        }
        break;
    }
    printf("Hello!");
    return 0;
}
Answer: 4 - show solution

At each iteration the parent (fork returns non-zero) breaks out and prints; only the child continues to the next iteration. i = 0: original forks, original prints (1). i = 1: child 1 forks, child 1 prints (2). i = 2: child 2 forks, child 2 prints (3). Child 3 continues, i becomes 3, loop ends, child 3 prints (4). This is a chain of 4 processes, each printing once. Answer: 4.

Concept: fork() returns 0 in the child. Here only children keep looping, giving a chain rather than a tree; assuming 2³ = 8 processes is the trap.

GATE 2026 S1 · Q64NAT2 marks · no negative· Moderate

Consider a CPU that has to execute two types of processes. The first type, Actuators (A), requires a CPU burst of 6 seconds. The second type, Controllers (C), requires a CPU burst of 8 seconds. A new process of type A arrives at time t = 10, 20, 30, 40, and 50 (in seconds). Similarly, a new process of type C arrives at time t = 11, 22, 33, 44, and 55 (in seconds). The CPU scheduling policy is First Come First Serve (FCFS). The first process of type A starts running at t = 10 seconds. The average waiting time (in seconds) for the 10 processes is ___________. (rounded off to one decimal place)

Answer: 9.5 - show solution

FCFS order by arrival: A10, C11, A20, C22, A30, C33, A40, C44, A50, C55. Start/finish: A10 10-16 (wait 0), C11 16-24 (5), A20 24-30 (4), C22 30-38 (8), A30 38-44 (8), C33 44-52 (11), A40 52-58 (12), C44 58-66 (14), A50 66-72 (16), C55 72-80 (17). Total waiting = 95. Average = 95/10 = 9.5 s. Answer: 9.5.

Concept: Waiting time = start time - arrival time under FCFS (non-preemptive). A Gantt chart avoids errors; the CPU is never idle here, so queueing builds up.

GATE 2026 S2 · Q23MCQ1 mark · -1/3· Easy

Which one of the following CPU scheduling algorithms cannot be preemptive?

  1. (A)Shortest Remaining Time First (SRTF) Scheduling
  2. (B)First Come First Serve (FCFS) Scheduling
  3. (C)Round Robin Scheduling
  4. (D)Priority Scheduling
Answer: B - show solution

SRTF is the preemptive version of SJF. Round Robin preempts on quantum expiry. Priority scheduling can be preemptive or not. FCFS runs each process to completion (or until it blocks) in arrival order and never preempts. Answer: (B).

Concept: Know which schedulers are inherently preemptive, inherently non-preemptive, or either. The trap is priority scheduling, which has both variants.

GATE 2026 S2 · Q51MSQ2 marks · no negative· Moderate

Consider three processes P1, P2, and P3 running identical code, as shown in the pseudocode below. A and B are two binary semaphores initialized to 1 and 0, respectively. X is a shared variable initialized to 0. Each line in the pseudocode is executed atomically. Assume that any of the three processes can start to execute first and context switching can happen between these processes at any arbitrary time and in any arbitrary order. Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?

Wait(A);
Print(*);
X = X+1;
If (X == 2)
   {
      Print($);
      Signal(B);
   }
Signal(A);
Wait(B);
Print(#);
Signal(B);
  1. (A)**$*###
  2. (B)**$#*##
  3. (C)**$##*#
  4. (D)***$###
Answer: A, B, C - show solution

The block from Wait(A) to Signal(A) is a critical section. The second process to enter prints * then $ and signals B before releasing A. So $ immediately follows the second *, and the third * can only come after $ - (D) is impossible. After $, B = 1 and each # is followed by Signal(B), so #s chain. (A): third process enters before any #: **$*###. (B): first waiter prints #, then third enters: **$#*##. (C): two #s, then third enters, then its #: **$##*#. All feasible. Answer: (A), (B) and (C).

Concept: Mutual exclusion on A forces * $ of the second process to be adjacent; B acts as a turnstile once opened. The trap is (D), which needs a third * inside another process's critical section.

GATE 2026 S2 · Q53NAT2 marks · no negative· Moderate

To keep track of free blocks in a file system, one of the two approaches is generally used - using bitmaps (bit vectors) or using linked lists. Consider that the linked list approach is used to keep track of free blocks in a file system. Assume that the disk size is 16 GB, block size is 2 KB, and block numbers used are 32-bit long. A single pointer of size 4 bytes is used in each block of the list to point to the next block of the list. The number of blocks required to hold the free disk block numbers is ____________. (answer in integer) Note: 1K = 2¹⁰ and 1G = 2³⁰

Answer: 16417 - show solution

Number of disk blocks = 16 GB / 2 KB = 2³⁴ / 2¹¹ = 2²³ = 8,388,608. Each list block holds (2048 - 4)/4 = 511 block numbers (4 bytes reserved for the next pointer). In the worst case (all blocks free) the list needs ceil(8,388,608 / 511) = ceil(16416.06) = 16417 blocks. Answer: 16417.

Concept: Grouped free-list sizing: subtract the next-pointer from each block's capacity and take the ceiling. Traps: using 512 entries per block (giving 16384) or forgetting to round up.

GATE 2026 S2 · Q54NAT2 marks · no negative· Moderate

A system has a Translation Lookaside Buffer (TLB) that has a reach of 1 MB. TLB reach is defined as the total amount of physical memory that can be accessed through the TLB entries. The paging system uses pages of size 4 KB. The virtual address space is 64 GB and physical address space is 1 GB. If each TLB entry stores a 4-bit process id, page number, frame number, and a 2-bit control field, then the size of the TLB (in bytes) is ___________. (answer in integer) Note: 1K = 2¹⁰, 1M = 2²⁰, 1G = 2³⁰

Answer: 1536 - show solution

Entries = reach / page size = 2²⁰ / 2¹² = 256. Page number bits = log₂(64 GB / 4 KB) = 36 - 12 = 24. Frame number bits = log₂(1 GB / 4 KB) = 30 - 12 = 18. Entry = 4 + 24 + 18 + 2 = 48 bits = 6 bytes. TLB size = 256 x 6 = 1536 bytes. Answer: 1536.

Concept: TLB reach = entries x page size, giving the entry count; each entry stores the full virtual page number (fully associative) plus frame number and extras. The trap is using the address widths (36, 30) instead of page/frame number widths.

GATE 2026 S2 · Q55NAT2 marks · no negative· Easy

Consider contiguous allocation of physical memory to processes using variable partitioning scheme. Suppose there are 8 holes in the memory of sizes 20 KB, 4 KB, 25 KB, 18 KB, 7 KB, 9 KB, 15 KB, and 12 KB. Assume that no two holes are adjacent. Two processes P1 of size 16 KB and P2 of size 9 KB arrive in that order, and they are allocated memory using the best-fit technique. After allocating space to P1 and P2, the number of holes of size less than 8 KB is ____________. (answer in integer) Note: 1K = 2¹⁰

Answer: 3 - show solution

Best fit for P1 (16 KB): smallest hole ≥ 16 is 18 KB, leaving a 2 KB hole. Best fit for P2 (9 KB): the 9 KB hole fits exactly, leaving no hole. Holes now: 20, 4, 25, 2, 7, 15, 12. Those below 8 KB: 4, 2, 7 = 3. Answer: 3.

Concept: Best fit picks the smallest adequate hole and tends to leave tiny fragments. The trap is counting a 0 KB leftover as a hole.

GATE 2025 S1 · Q14MCQ1 mark · -1/3· Easy

Consider a demand paging memory management system with 32-bit logical address, 20-bit physical address, and page size of 2048 bytes. Assuming that the memory is byte addressable, what is the maximum number of entries in the page table?

  1. (A)2²¹
  2. (B)2²⁰
  3. (C)2²²
  4. (D)2²⁴
Answer: A - show solution

Page size 2048 = 2¹¹ bytes, so the offset is 11 bits. A single-level page table has one entry per logical page: 2³² / 2¹¹ = 2²¹ entries. The 20-bit physical address only affects the frame-number width (20 - 11 = 9 bits per entry), not the entry count. Answer: 2²¹ (A).

Concept: Page table entries = number of virtual pages. The trap is dividing the physical address space instead (2⁹ frames), which sizes each entry, not the table.

GATE 2025 S1 · Q29NAT1 mark · no negative· Easy

Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into I/O queue whenever an I/O related operation is performed. Assume that there will always be a context switch whenever a process requests for an I/O, and also whenever the process returns from an I/O. The number of times the process will enter the ready queue during its lifetime (not counting the time the process enters the ready queue when it is run initially) is _______. (Answer in integer)

int main()
{
    int x=0,i=0;
    scanf("%d",&x);
    for(i=0; i<20; i++)
    {
        x = x+20;
        printf("%d\n",x);
    }
    return 0;
}
Answer: 21 - show solution

Each I/O call sends the process to the I/O queue; when the I/O completes it returns to the ready queue. I/O operations: one scanf, plus printf executed 20 times in the loop = 21 I/O operations. Each produces one entry into the ready queue. return 0 terminates the process, no further entry. Answer: 21.

Concept: Process state transitions: running to waiting on I/O, waiting to ready on completion. Traps: forgetting the scanf (20) or counting the initial admission.

GATE 2025 S1 · Q38MCQ2 marks · -2/3· Moderate

A computer has two processors, M1 and M2. Four processes P1, P2, P3, P4 with CPU bursts of 20, 16, 25, and 10 milliseconds, respectively, arrive at the same time and these are the only processes in the system. The scheduler uses non-preemptive priority scheduling, with priorities decided as follows: - M1 uses priority of execution for the processes as, P1 > P3 > P2 > P4, i.e., P1 and P4 have highest and lowest priorities, respectively. - M2 uses priority of execution for the processes as, P2 > P3 > P4 > P1, i.e., P2 and P1 have highest and lowest priorities, respectively. A process Pi is scheduled to a processor Mk, if the processor is free and no other process Pj is waiting with higher priority. At any given point of time, a process can be allocated to any one of the free processors without violating the execution priority rules. Ignore the context switch time. What will be the average waiting time of the processes in milliseconds?

  1. (A)9.00
  2. (B)8.75
  3. (C)6.50
  4. (D)7.50
Answer: A - show solution

t = 0: both free. M1 takes its top choice P1 (0-20); M2 takes its top choice P2 (0-16). t = 16: M2 free, waiting P3 and P4; by M2's order P3 > P4, so P3 runs 16-41. t = 20: M1 free, only P4 waits, P4 runs 20-30. Waiting times: P1 0, P2 0, P3 16, P4 20. Average = 36 / 4 = 9.00 ms. Answer: 9.00 (A).

Concept: Multiprocessor non-preemptive priority with per-processor priority orders. The key step is applying M2's order at t = 16, not M1's.

GATE 2025 S1 · Q51NAT2 marks · no negative· Moderate

A disk of size 512M bytes is divided into blocks of 64K bytes. A file is stored in the disk using linked allocation. In linked allocation, each data block reserves 4 bytes to store the pointer to the next data block. The link part of the last data block contains a NULL pointer (also of 4 bytes). Suppose a file of 1M bytes needs to be stored in the disk. Assume, 1K = 2¹⁰ and 1M = 2²⁰. The amount of space in bytes that will be wasted due to internal fragmentation is ______. (Answer in integer)

Answer: 65468 - show solution

Data per block = 65536 - 4 = 65532 bytes. File = 1048576 bytes. 16 blocks hold 16 x 65532 = 1048512 bytes, leaving 64 bytes, so a 17th block is needed. That block uses 64 data bytes out of 65532, wasting 65532 - 64 = 65468 bytes. Answer: 65468.

Concept: Internal fragmentation is the unused data area of the last block. The trap is ignoring the 4-byte pointer (16 blocks would seem to fit exactly, giving 0).

GATE 2025 S1 · Q54NAT2 marks · no negative· Moderate

In optimal page replacement algorithm, information about all future page references is available to the operating system (OS). A modification of the optimal page replacement algorithm is as follows: The OS correctly predicts only up to next 4 page references (including the current page) at the time of allocating a frame to a page. A process accesses the pages in the following order of page numbers: 1, 3, 2, 4, 2, 3, 1, 2, 4, 3, 1, 4. If the system has three memory frames that are initially empty, the number of page faults that will occur during execution of the process is ________. (Answer in integer)

Answer: 6 - show solution

1, 3, 2: 3 faults, frames {1, 3, 2}. Ref 4 (4th): window 4, 2, 3, 1 - all resident pages appear; 1 is used last, replace 1: {4, 3, 2}. 2, 3 hit. Ref 1 (7th): window 1, 2, 4, 3; 3 used last, replace 3: {4, 1, 2}. 2, 4 hit. Ref 3 (10th): window 3, 1, 4 (end of string); 2 does not appear, replace 2: {4, 1, 3}. 1, 4 hit. Faults: 3 + 1 + 1 + 1 = 6. Answer: 6.

Concept: Optimal replacement limited to a lookahead window: evict a page absent from the window, else the one used furthest within it. Here the window never misleads, so the count matches full OPT.

GATE 2025 S2 · Q26MCQ1 mark · -1/3· Moderate

Processes P1, P2, P3, P4 arrive in that order at times 0, 1, 2, and 8 milliseconds respectively, and have execution times of 10, 13, 6, and 9 milliseconds respectively. Shortest Remaining Time First (SRTF) algorithm is used as the CPU scheduling policy. Ignore context switching times. Which ONE of the following correctly gives the average turnaround time of the four processes in milliseconds?

  1. (A)22
  2. (B)15
  3. (C)37
  4. (D)19
Answer: D - show solution

t=0 P1 starts. t=1 P2 (13) arrives; P1 has 9 left, continues. t=2 P3 (6) arrives; P1 has 8 left, so P3 preempts and runs 2-8. t=8 P4 (9) arrives; remaining P1 8, P2 13, P4 9, so P1 runs 8-16. Then P4 16-25, P2 25-38. Turnaround: P1 16, P2 38-1 = 37, P3 8-2 = 6, P4 25-8 = 17. Average = 76/4 = 19 ms. Answer: (D) 19.

Concept: SRTF re-decides at every arrival using remaining time. The trap is using original burst times, or forgetting to subtract arrival times; 37 is P2's turnaround alone.

GATE 2025 S2 · Q47MSQ2 marks · no negative· Hard

Consider a demand paging system with three frames, and the following page reference string: 1 2 3 4 5 4 1 6 4 5 1 3 2. The contents of the frames are as follows initially and after each reference (from left to right): Reference: - 1* 2* 3* 4* 5* 4 1 6* 4 5 1* 3* 2* Frame 1: - 1 1 1 1 1 1 1 6 6 6 6 6 2 Frame 2: - - 2 2 4 4 4 4 4 4 4 1 1 1 Frame 3: - - - 3 3 5 5 5 5 5 5 5 3 3 The *-marked references cause page faults (replacements once the frames are full). Which one or more of the following could be the page replacement policy/policies in use?

  1. (A)Least Recently Used page replacement policy
  2. (B)Least Frequently Used page replacement policy
  3. (C)Most Frequently Used page replacement policy
  4. (D)Optimal page replacement policy
Answer: D - show solution

At reference 4, frames hold 1, 2, 3 and page 2 is evicted. LRU would evict 1 (least recently used): LRU fails. Optimal: next uses are 1 at position 7, 3 at 12, 2 at 13, so evict 2: matches. At 5, frames 1, 4, 3: next uses 4 at 6, 1 at 7, 3 at 12, evict 3: matches. At 6, frames 1, 4, 5: next uses 4 at 9, 5 at 10, 1 at 11, evict 1: matches. The last three faults find no resident page used again, so any choice is optimal. LFU: at reference 6, page 5 has been used once while 1 and 4 twice, so LFU evicts 5, not 1: fails. MFU: at reference 4 all counts are 1 and the usual FIFO tie-break evicts 1, not 2; with cumulative counts it also evicts 1 at reference 3 instead of 5: fails. Answer: (D).

Concept: Check each policy at the first fault where it would decide differently. Optimal looks forward and evicts the page used farthest in the future. The trap is accepting a policy only through arbitrary tie-breaking.

GATE 2025 S2 · Q48MSQ2 marks · no negative· Moderate

P = {P1, P2, P3, P4} consists of all active processes in an operating system. R = {R1, R2, R3, R4} consists of single instances of distinct types of resources in the system. The resource allocation graph has the following assignment and claim edges. Assignment edges: R1 → P1, R2 → P2, R3 → P3, R4 → P4 (the assignment edge R1 → P1 means resource R1 is assigned to process P1, and so on for others). Claim edges: P1 → R2, P2 → R3, P3 → R1, P2 → R4, P4 → R2 (the claim edge P1 → R2 means process P1 is waiting for resource R2, and so on for others). Which of the following statement(s) is/are CORRECT?

  1. (A)Aborting P1 makes the system deadlock free.
  2. (B)Aborting P3 makes the system deadlock free.
  3. (C)Aborting P2 makes the system deadlock free.
  4. (D)Aborting P1 and P4 makes the system deadlock free.
Answer: C, D - show solution

With single-instance resources, use the wait-for graph: P1 → P2 (R2), P2 → P3 (R3), P3 → P1 (R1), P2 → P4 (R4), P4 → P2 (R2). Cycles: P1-P2-P3-P1 and P2-P4-P2. (A) Aborting P1 leaves the P2-P4 cycle. (B) Aborting P3 leaves the P2-P4 cycle. (C) P2 lies on both cycles; aborting it releases R2, so P1 and P4 can finish, then P3. Deadlock free. (D) Aborting P1 and P4 frees R1 and R4: P3 gets R1 and finishes, releasing R3, then P2 finishes. Deadlock free. Answer: (C) and (D).

Concept: With one instance per resource, a cycle means deadlock. To recover, every cycle must be broken; pick a process common to all cycles or a set covering them.

GATE 2025 S2 · Q58NAT2 marks · no negative· Moderate

A computer system supports a logical address space of 2³² bytes. It uses two-level hierarchical paging with a page size of 4096 bytes. A logical address is divided into a b-bit index to the outer page table, an offset within the page of the inner page table, and an offset within the desired page. Each entry of the inner page table uses eight bytes. All the pages in the system have the same size. The value of b is ___________. (Answer in integer)

Answer: 11 - show solution

Page offset = log2(4096) = 12 bits. One page of the inner page table holds 4096 / 8 = 512 entries, so the inner index is 9 bits. Outer index b = 32 - 12 - 9 = 11. Answer: 11.

Concept: Each inner page table occupies exactly one page, so its index width is log2(page size / entry size). The trap is assuming 4-byte entries, which gives 10.

GATE 2024 S1 · Q24MSQ1 mark · no negative· Easy

Which of the following statements about threads is/are TRUE?

  1. (A)Threads can only be implemented in kernel space
  2. (B)Each thread has its own file descriptor table for open files
  3. (C)All the threads belonging to a process share a common stack
  4. (D)Threads belonging to a process are by default not protected from each other
Answer: D - show solution

(A) False: user-level threads exist. (B) False: the file descriptor table belongs to the process and is shared by its threads. (C) False: each thread has its own stack. (D) True: threads share one address space, so one thread can read or corrupt another's data. Answer: (D).

Concept: Threads share code, data, heap and open files; each has its own registers, PC and stack. The trap is assuming a shared stack or per-thread file table.

GATE 2024 S1 · Q25MSQ1 mark · no negative· Easy

Which of the following process state transitions is/are NOT possible?

  1. (A)Running to Ready
  2. (B)Waiting to Running
  3. (C)Ready to Waiting
  4. (D)Running to Terminated
Answer: B, C - show solution

Running to Ready happens on preemption. Running to Terminated happens on exit. Waiting (blocked) to Running is impossible: when the event occurs the process goes to Ready and must be dispatched. Ready to Waiting is impossible: a process can block only by doing something while running. Answer: (B), (C).

Concept: Only a running process can block, and an unblocked process always returns to the ready queue first. The trap is allowing a direct wake-up into Running.

GATE 2024 S1 · Q40MCQ2 marks · -2/3· Moderate

Consider the following two threads T1 and T2 that update two shared variables a and b. Assume that initially a = b = 1. Though context switching between threads can happen at any time, each statement of T1 or T2 is executed atomically without interruption. T1: a = a + 1; b = b + 1; T2: b = 2 * b; a = 2 * a; Which one of the following options lists all the possible combinations of values of a and b after both T1 and T2 finish execution?

  1. (A)(a = 4, b = 4); (a = 3, b = 3); (a = 4, b = 3)
  2. (B)(a = 3, b = 4); (a = 4, b = 3); (a = 3, b = 3)
  3. (C)(a = 4, b = 4); (a = 4, b = 3); (a = 3, b = 4)
  4. (D)(a = 2, b = 2); (a = 2, b = 3); (a = 3, b = 4)
Answer: A - show solution

Each variable is touched once by each thread, so only the relative order on each variable matters. For a: (a+1 then 2a) gives 4, (2a then a+1) gives 3. For b: (2b then b+1) gives 3, (b+1 then 2b) gives 4. Program order forbids 2a before a+1 together with b+1 before 2b (that would need a cycle), so (3, 4) is impossible. Enumerating all 6 interleavings gives (4, 4), (4, 3) four times, and (3, 3). Answer: (A).

Concept: Enumerate interleavings respecting each thread's program order. The trap is including (a = 3, b = 4), which needs T2's second statement before T1's first while T1's second precedes T2's first.

GATE 2024 S1 · Q54NAT2 marks · no negative· Easy

Consider a 512 GB hard disk with 32 storage surfaces. There are 4096 sectors per track and each sector holds 1024 bytes of data. The number of cylinders in the hard disk is _________

Answer: 4096 - show solution

Capacity per track = 4096 × 1024 B = 2²² B. Per cylinder (32 surfaces) = 2²⁷ B. 512 GB = 2³⁹ B. Cylinders = 2³⁹ / 2²⁷ = 2¹² = 4096. Answer: 4096.

Concept: Cylinders = capacity / (surfaces × sectors per track × bytes per sector). The trap is dividing by tracks per surface or forgetting the surfaces.

GATE 2024 S1 · Q57NAT2 marks · no negative· Moderate

Consider the following code snippet using the fork() and wait() system calls. Assume that the code compiles and runs correctly, and that the system calls run successfully without any errors. The total number of times the printf statement is executed is _______

int x = 3;
while(x > 0) {
  fork();
  printf("hello");
  wait(NULL);
  x--;
}
Answer: 14 - show solution

Every process alive at the start of an iteration forks, and both parent and child print and continue the loop. Processes double each iteration: 2 print in iteration 1, 4 in iteration 2, 8 in iteration 3. wait() only affects ordering. Total = 2 + 4 + 8 = 14. Answer: 14.

Concept: With fork inside a loop, each iteration doubles the processes and each of them executes the printf. The trap is counting only the final 8 processes.

GATE 2024 S1 · Q62NAT2 marks · no negative· Easy

Consider a memory management system that uses a page size of 2 KB. Assume that both the physical and virtual addresses start from 0. Assume that the pages 0, 1, 2, and 3 are stored in the page frames 1, 3, 2, and 0, respectively. The physical address (in decimal format) corresponding to the virtual address 2500 (in decimal format) is _________

Answer: 6596 - show solution

Page size 2048 B. Virtual address 2500 is in page ⌊2500/2048⌋ = 1 with offset 452. Page 1 is in frame 3, so physical address = 3 × 2048 + 452 = 6596. Answer: 6596.

Concept: Split the address into page number and offset, map the page to its frame, keep the offset. The trap is mapping page 1 to frame 1.

GATE 2024 S2 · Q24MSQ1 mark · no negative· Easy

Which of the following tasks is/are the responsibility/responsibilities of the memory management unit (MMU) in a system with paging-based memory management?

  1. (A)Allocate a new page table for a newly created process
  2. (B)Translate a virtual address to a physical address using the page table
  3. (C)Raise a trap when a virtual address is not found in the page table
  4. (D)Raise a trap when a process tries to write to a page marked with read-only permission in the page table
Answer: B, C, D - show solution

The MMU is hardware: it uses the page table to translate virtual to physical addresses (B), raises a page-fault trap when the mapping is absent or invalid (C), and raises a protection trap on a write to a read-only page (D). Allocating a page table for a new process is a software task of the OS kernel, so (A) is not the MMU's job. Answer: (B), (C), (D).

Concept: Division of labour: the hardware MMU translates, checks and traps; the OS allocates, sets up tables and handles the traps.

GATE 2024 S2 · Q25MSQ1 mark · no negative· Moderate

Consider a process P running on a CPU. Which one or more of the following events will always trigger a context switch by the OS that results in process P moving to a non-running state (e.g., ready, blocked)?

  1. (A)P makes a blocking system call to read a block of data from the disk
  2. (B)P tries to access a page that is in the swap space, triggering a page fault
  3. (C)An interrupt is raised by the disk to deliver data requested by some other process
  4. (D)A timer interrupt is raised by the hardware
Answer: A, B - show solution

(A) A blocking disk read must wait for I/O, so P is always blocked. (B) The page is in swap space, so it must be read from disk and P blocks until it arrives. (C) The disk interrupt is serviced and the other process becomes ready, but P may simply resume - not always a switch. (D) A timer interrupt preempts P only if its time slice has expired and another process is ready; otherwise P continues. Answer: (A), (B).

Concept: 'Always' is the key word: events that make P wait for I/O always remove it from the CPU; interrupts only sometimes lead to preemption.

GATE 2024 S2 · Q37MCQ2 marks · -2/3· Moderate

Consider a single processor system with four processes A, B, C, and D, represented as given below, where for each process the first value is its arrival time, and the second value is its CPU burst time. A (0, 10), B (2, 6), C (4, 3), and D (6, 7). Which one of the following options gives the average waiting times when preemptive Shortest Remaining Time First (SRTF) and Non-Preemptive Shortest Job First (NP-SJF) CPU scheduling algorithms are applied to the processes?

  1. (A)SRTF = 6, NP-SJF = 7
  2. (B)SRTF = 6, NP-SJF = 7.5
  3. (C)SRTF = 7, NP-SJF = 7.5
  4. (D)SRTF = 7, NP-SJF = 8.5
Answer: B - show solution

SRTF: A 0-2; B arrives (6 < 8) B 2-4; C arrives (3 < 4) C 4-7; then B (4 left) 7-11; D 11-18; A 18-26. Waiting = completion − arrival − burst: A 26−0−10 = 16, B 11−2−6 = 3, C 7−4−3 = 0, D 18−6−7 = 5. Average 24/4 = 6. NP-SJF: A 0-10; at 10 pick C 10-13, B 13-19, D 19-26. Waiting: A 0, B 11, C 6, D 13. Average 30/4 = 7.5. Answer: (B) SRTF = 6, NP-SJF = 7.5.

Concept: Gantt charts for preemptive vs non-preemptive SJF. In SRTF, re-check at every arrival; in NP-SJF the long first job runs to completion.

GATE 2024 S2 · Q46MSQ2 marks · no negative· Moderate

Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below. Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?

// code of T1        // code of T2
wait(s1);            wait(s1);
x = x+1;             x = x+1;
print(x);            print(x);
wait(s2);            signal(s2);
signal(s1);          signal(s1);
  1. (A)T1 runs first and prints 1, T2 runs next and prints 2
  2. (B)T2 runs first and prints 1, T1 runs next and prints 2
  3. (C)T1 runs first and prints 1, T2 does not print anything (deadlock)
  4. (D)T2 runs first and prints 1, T1 does not print anything (deadlock)
Answer: B, C - show solution

If T1 enters first: it takes s1, prints 1, then blocks on wait(s2) (s2 = 0) while still holding s1. T2 blocks on wait(s1). Deadlock, T2 prints nothing: (C) possible, (A) impossible. If T2 enters first: it takes s1, prints 1, signals s2 (s2 = 1) and s1. T1 then enters, prints 2, wait(s2) succeeds, signals s1. So (B) possible and (D) impossible. Answer: (B), (C).

Concept: Holding a mutex while waiting on another semaphore that only the blocked thread can signal is a classic deadlock. Trace both entry orders.

GATE 2024 S2 · Q53NAT2 marks · no negative· Moderate

Consider a disk with the following specifications: rotation speed of 6000 RPM, average seek time of 5 milliseconds, 500 sectors/track, 512-byte sectors. A file has content stored in 3000 sectors located randomly on the disk. Assuming average rotational latency, the total time (in seconds, rounded off to 2 decimal places) to read the entire file from the disk is _________

Answer: 29.5 to 30.5 - show solution

6000 RPM = 100 rotations per second, so one rotation = 10 ms and average rotational latency = 5 ms. Transfer of one sector = 10 ms / 500 = 0.02 ms. Sectors are random, so each needs seek + latency + transfer = 5 + 5 + 0.02 = 10.02 ms. Total = 3000 × 10.02 ms = 30.06 s. The official key accepts 29.5 to 30.5 (ignoring the tiny transfer time gives 30.00). Answer: 30.06.

Concept: For randomly placed sectors every access pays the full seek and half-rotation latency. The trap is treating the file as contiguous and paying seek once.

GATE 2024 S2 · Q64NAT2 marks · no negative· Moderate

Consider a 32-bit system with 4 KB page size and page table entries of size 4 bytes each. Assume 1 KB = 2¹⁰ bytes. The OS uses a 2-level page table for memory management, with the page table containing an outer page directory and an inner page table. The OS allocates a page for the outer page directory upon process creation. The OS uses demand paging when allocating memory for the inner page table, i.e., a page of the inner page table is allocated only if it contains at least one valid page table entry. An active process in this system accesses 2000 unique pages during its execution, and none of the pages are swapped out to disk. After it completes the page accesses, let X denote the minimum and Y denote the maximum number of pages across the two levels of the page table of the process. The value of X+Y is ________

Answer: 1028 - show solution

A 4 KB page holds 4096/4 = 1024 entries, so each inner page-table page maps 1024 pages and the directory has 1024 entries (2²⁰ pages total). Minimum: 2000 pages packed contiguously need ⌈2000/1024⌉ = 2 inner pages, plus the directory: X = 3. Maximum: spread the pages so each inner page has as few valid entries as possible, but there are only 1024 inner pages possible: Y = 1024 + 1 = 1025. X + Y = 1028. Answer: 1028.

Concept: Two-level paging bounds: dense placement minimises inner tables; sparse placement is capped by the directory's 1024 entries, not by 2000.

GATE 2023 · Q22MSQ1 mark · no negative· Easy

Which one or more of the following need to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process?

  1. (A)Page table base register
  2. (B)Stack pointer
  3. (C)Program counter
  4. (D)General purpose registers
Answer: B, C, D - show solution

Threads of the same process share the address space, so the page table base register does not change and need not be saved. Each thread has its own execution context: its own stack (stack pointer), its own next instruction (program counter) and its own register values (general purpose registers). These must be saved for T1 and restored for T2. Answer: (B), (C), (D).

Concept: Thread context = PC, SP, registers; process context additionally includes the address space. The trap is including the page table base register, which only changes on a process switch.

GATE 2023 · Q23MSQ1 mark · no negative· Easy

Which one or more of the following options guarantee that a computer system will transition from user mode to kernel mode?

  1. (A)Function Call
  2. (B)malloc Call
  3. (C)Page Fault
  4. (D)System Call
Answer: C, D - show solution

A function call is an ordinary jump within user mode. malloc is a library routine that usually serves requests from memory already obtained by the process and only sometimes calls brk/mmap, so it does not guarantee a mode switch. A page fault is an exception that always traps into the kernel's fault handler. A system call executes a trap instruction that always switches to kernel mode. Answer: (C) and (D).

Concept: Only traps, exceptions and interrupts guarantee entry to kernel mode. The trap is malloc: it may make a system call, but not on every invocation.

GATE 2023 · Q38MCQ2 marks · -2/3· Moderate

Consider the two functions incr and decr shown below. There are 5 threads each invoking incr once, and 3 threads each invoking decr once, on the same shared variable X. The initial value of X is 10. Suppose there are two implementations of the semaphore s, as follows: I-1: s is a binary semaphore initialized to 1. I-2: s is a counting semaphore initialized to 2. Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively. Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?

incr(){
    wait(s);
    X = X+1;
    signal(s);
}

decr(){
    wait(s);
    X = X-1;
    signal(s);
}
  1. (A)15, 7
  2. (B)7, 7
  3. (C)12, 7
  4. (D)12, 8
Answer: C - show solution

I-1: a binary semaphore gives mutual exclusion, so every update takes effect: V1 = 10 + 5 - 3 = 12. I-2: two threads can be inside together, so X = X ± 1 (read, modify, write) can race. Minimum: decr1 reads X = 10 and pauses. Through the other slot all 5 incr run one after another, X = 15. decr1 now writes 10 - 1 = 9, wiping out all increments. The remaining two decr run serially: 8, 7. Nothing lower is possible, since only 3 decrements exist and every write is some read value ± 1. V2 = 7. Answer: (C) 12, 7.

Concept: A counting semaphore initialised to 2 is not a mutex, so lost updates are possible. To minimise, let one stale decrement overwrite all the increments.

GATE 2023 · Q57NAT2 marks · no negative· Moderate

Consider the following two-dimensional array D in the C programming language, which is stored in row-major order: int D[128][128]; Demand paging is used for allocating memory and each physical page frame holds 512 elements of the array D. The Least Recently Used (LRU) page-replacement policy is used by the operating system. A total of 30 physical page frames are allocated to a process which executes the following code snippet. The number of page faults generated during the execution of this code snippet is ________.

for (int i = 0; i < 128; i++)
    for (int j = 0; j < 128; j++)
        D[j][i] *= 10;
Answer: 4096 - show solution

A row has 128 elements, so one page holds 4 rows; the array spans 128/4 = 32 pages. The inner loop walks down column i, touching rows 0..127, i.e. pages 0..31 in order (4 consecutive accesses per page). With only 30 frames under LRU, a cyclic reference to 32 pages faults on every new page: when page p is needed again it was the least recently used one evicted. So each outer iteration causes 32 faults: 128 × 32 = 4096. Answer: 4096.

Concept: Column-wise access to a row-major array crosses pages constantly. LRU with fewer frames than the cyclic working set degenerates to a fault on every page change.

GATE 2023 · Q58NAT2 marks · no negative· Moderate

Consider a computer system with 57-bit virtual addressing using multi-level tree-structured page tables with L levels for virtual to physical address translation. The page size is 4 KB (1 KB = 1024 B) and a page table entry at any of the levels occupies 8 bytes. The value of L is .

Answer: 5 - show solution

Page size 4 KB = 2¹² bytes, so the offset uses 12 bits and the virtual page number has 57 - 12 = 45 bits. Each page-table page fits in one page: 4096 / 8 = 512 = 2⁹ entries, so each level resolves 9 bits. Levels L = 45 / 9 = 5. Answer: 5.

Concept: Multi-level paging: bits per level = log2(page size / PTE size). This 57-bit, 5-level layout is exactly x86-64 five-level paging.

GATE 2022 · Q19MCQ1 mark · -1/3· Easy

Consider the following threads, T1, T2, and T3 executing on a single processor, synchronized using three binary semaphore variables, S1, S2, and S3, operated upon using standard wait() and signal(). The threads can be context switched in any order and at any time. Which initialization of the semaphores would print the sequence BCABCABCA....?

T1                    T2                    T3
while(true){          while(true){          while(true){
   wait(S3);             wait(S1);             wait(S2);
   print("C");           print("B");           print("A");
   signal(S2); }         signal(S3); }         signal(S1); }
  1. (A)S1 = 1; S2 = 1; S3 = 1
  2. (B)S1 = 1; S2 = 1; S3 = 0
  3. (C)S1 = 1; S2 = 0; S3 = 0
  4. (D)S1 = 0; S2 = 1; S3 = 1
Answer: C - show solution

B must come first, so only T2 may proceed initially: S1 = 1 and S2 = S3 = 0. Then T2 prints B and signals S3, enabling only T1, which prints C and signals S2, enabling only T3, which prints A and signals S1, enabling T2 again. The cycle BCA repeats with exactly one semaphore at 1 at any time. Any initialization with two semaphores at 1 lets another thread print first or interleave. Answer: (C) S1 = 1; S2 = 0; S3 = 0.

Concept: A token-passing ring of semaphores enforces a strict order only if exactly one token exists. The trap is (B), where T3 could print A before B.

GATE 2022 · Q26MSQ1 mark · no negative· Moderate

Which of the following statements is/are TRUE with respect to deadlocks?

  1. (A)Circular wait is a necessary condition for the formation of deadlock.
  2. (B)In a system where each resource has more than one instance, a cycle in its wait-for graph indicates the presence of a deadlock.
  3. (C)If the current allocation of resources to processes leads the system to unsafe state, then deadlock will necessarily occur.
  4. (D)In the resource-allocation graph of a system, if every edge is an assignment edge, then the system is not in deadlock state.
Answer: A, D - show solution

(A) True: circular wait is one of the four Coffman necessary conditions. (B) False: with multiple instances per resource, a cycle is necessary but not sufficient for deadlock. (C) False: an unsafe state may lead to deadlock, but processes may release resources early, so deadlock is not certain. (D) True: if every edge is an assignment edge, no process is waiting for anything, so no deadlock. Answer: (A), (D).

Concept: Cycle implies deadlock only for single-instance resources; unsafe does not mean deadlocked. Deadlock needs some process waiting.

GATE 2022 · Q38MCQ2 marks · -2/3· Moderate

Which one of the following statements is FALSE?

  1. (A)The TLB performs an associative search in parallel on all its valid entries using page number of incoming virtual address.
  2. (B)If the virtual address of a word given by CPU has a TLB hit, but the subsequent search for the word results in a cache miss, then the word will always be present in the main memory.
  3. (C)The memory access time using a given inverted page table is always same for all incoming virtual addresses.
  4. (D)In a system that uses hashed page tables, if two distinct virtual addresses V1 and V2 map to the same value while hashing, then the memory access time of these addresses will not be the same.
Answer: C - show solution

(A) True: a TLB is associative memory, searched in parallel on the page number. (B) True: a TLB hit means the page is mapped to a frame, i.e. resident in main memory, so a cache miss is served from main memory. (C) False: an inverted page table is searched for the (process, page) entry - linearly or via a hash with chains - so lookup time depends on where the entry is found and varies across addresses. (D) True: colliding addresses share a hash chain, so one is found later than the other. Answer: (C).

Concept: Inverted and hashed page tables trade memory for variable lookup time. Note the question asks for the FALSE statement.

GATE 2022 · Q42MCQ2 marks · -2/3· Hard

Consider four processes P, Q, R, and S scheduled on a CPU as per round robin algorithm with a time quantum of 4 units. The processes arrive in the order P, Q, R, S, all at time t = 0. There is exactly one context switch from S to Q, exactly one context switch from R to Q, and exactly two context switches from Q to R. There is no context switch from S to P. Switching to a ready process after the termination of another process is also considered a context switch. Which one of the following is NOT possible as CPU burst time (in time units) of these processes?

  1. (A)P = 4, Q = 10, R = 6, S = 2
  2. (B)P = 2, Q = 9, R = 5, S = 1
  3. (C)P = 4, Q = 12, R = 5, S = 4
  4. (D)P = 3, Q = 7, R = 7, S = 3
Answer: D - show solution

Simulate RR, quantum 4, queue P, Q, R, S. (A) P4 Q10 R6 S2: P(done) → Q(6 left) → R(2 left) → S(done) → Q(2 left) → R(done) → Q. Switches S→Q 1, R→Q 1, Q→R 2, no S→P: possible. (B) P2 Q9 R5 S1: P → Q(5) → R(1) → S → Q(1) → R → Q: same pattern, possible. (C) P4 Q12 R5 S4: P → Q(8) → R(1) → S → Q(4) → R → Q: possible. (D) P3 Q7 R7 S3: P → Q(3 left) → R(3 left) → S → Q(finishes) → R. There is no R→Q switch, violating 'exactly one R→Q'. Answer: (D) P = 3, Q = 7, R = 7, S = 3.

Concept: Trace the ready queue and record every switch, including switches after termination. The constraints amount to Q needing a third CPU turn after R's second turn.

GATE 2022 · Q63NAT2 marks · no negative· Moderate

Consider two files systems A and B, that use contiguous allocation and linked allocation, respectively. A file of size 100 blocks is already stored in A and also in B. Now, consider inserting a new block in the middle of the file (between 50th and 51st block), whose data is already available in the memory. Assume that there are enough free blocks at the end of the file and that the file control blocks are already in memory. Let the number of disk accesses required to insert a block in the middle of the file in A and B are nA and nB, respectively, then the value of nA + nB is_________.

Answer: 153 - show solution

Contiguous (A): blocks 51-100 must each move one place right: 50 reads + 50 writes, then write the new block in position 51: nA = 101. Linked (B): follow pointers from the start to block 50: 50 reads; write the new block with its pointer set to old block 51: 1 write; rewrite block 50 with its pointer to the new block: 1 write. nB = 52. nA + nB = 153. Answer: 153.

Concept: Contiguous allocation pays for shifting; linked allocation pays for traversal. A trap is forgetting the write-back of block 50's updated pointer.

GATE 2022 · Q64NAT2 marks · no negative· Easy

Consider a demand paging system with four page frames (initially empty) and LRU page replacement policy. For the following page reference string 7, 2, 7, 3, 2, 5, 3, 4, 6, 7, 7, 1, 5, 6, 1 the page fault rate, defined as the ratio of number of page faults to the number of memory accesses (rounded off to one decimal place) is_________.

Answer: 0.6 - show solution

7 F, 2 F, 7 H, 3 F, 2 H, 5 F (frames 7,2,3,5), 3 H, 4 F evicts 7 (LRU), 6 F evicts 2, 7 F evicts 5, 7 H, 1 F evicts 3, 5 F evicts 4, 6 H, 1 H. Faults = 9 out of 15 references. Rate = 9/15 = 0.6. Answer: 0.6.

Concept: LRU evicts the page whose last use is oldest. Track last-use times carefully after hits; a hit refreshes recency.

GATE 2018 · Q20MCQ1 mark · -1/3· Easy

Consider a process executing on an operating system that uses demand paging. The average time for a memory access in the system is M units if the corresponding memory page is available in memory, and D units if the memory access causes a page fault. It has been experimentally measured that the average time taken for a memory access in the process is X units. Which one of the following is the correct expression for the page fault rate experienced by the process?

  1. (A)(D - M) / (X - M)
  2. (B)(X - M) / (D - M)
  3. (C)(D - X) / (D - M)
  4. (D)(X - M) / (D - X)
Answer: B - show solution

Let p be the page fault rate. Effective access time X = (1 - p)M + pD = M + p(D - M). Solving, p = (X - M)/(D - M). Sanity check: X = M gives p = 0 and X = D gives p = 1. Answer: (B).

Concept: Effective memory access time is a weighted average of hit and fault times. The trap is inverting the fraction; checking the limits p = 0 and p = 1 catches it immediately.

GATE 2018 · Q34NAT1 mark · no negative· Easy

Consider a system with 3 processes that share 4 instances of the same resource type. Each process can request a maximum of K instances. Resource instances can be requested and released only one at a time. The largest value of K that will always avoid deadlock is ____.

Answer: 2 - show solution

The worst case is every process holding K - 1 instances and waiting for one more. Deadlock is impossible if even then one instance is free: 3(K - 1) + 1 ≤ 4, so K ≤ 2. With K = 3, two processes could hold 2 each, leaving 0 free, and both wait forever. Answer: 2.

Concept: For n processes each needing at most K of R instances, deadlock freedom needs n(K - 1) + 1 ≤ R. The trap is using n × K ≤ R, which is sufficient but far too strict.

GATE 2018 · Q49MCQ2 marks · -2/3· Moderate

In a system, there are three types of resources: E, F and G. Four processes P₀, P₁, P₂ and P₃ execute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, Max[P₂,F] is the maximum number of instances of F that P₂ would require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation. Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of E and 3 instances of F are the only resources available. Allocation Max E F G E F G P₀ 1 0 1 4 3 1 P₁ 1 1 2 2 1 4 P₂ 1 0 3 1 3 3 P₃ 2 0 0 5 4 1 From the perspective of deadlock avoidance, which one of the following is true?

  1. (A)The system is in safe state.
  2. (B)The system is not in safe state, but would be safe if one more instance of E were available
  3. (C)The system is not in safe state, but would be safe if one more instance of F were available
  4. (D)The system is not in safe state, but would be safe if one more instance of G were available
Answer: A - show solution

Need = Max - Allocation: P₀ (3,3,0), P₁ (1,0,2), P₂ (0,3,0), P₃ (3,4,1). Available (3,3,0). P₀'s need (3,3,0) fits; it finishes and releases (1,0,1): Available (4,3,1). P₂ needs (0,3,0): fits; releases (1,0,3): Available (5,3,4). P₁ needs (1,0,2): fits; releases (1,1,2): Available (6,4,6). P₃ needs (3,4,1): fits. Safe sequence P₀, P₂, P₁, P₃ exists, so the state is safe. Answer: (A).

Concept: Banker's safety algorithm: compute Need, then repeatedly run any process whose Need fits Available and reclaim its Allocation. The trap is comparing Max (not Need) with Available, which makes the state look unsafe.

GATE 2018 · Q50MCQ2 marks · -2/3· Easy

Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is N. Three semaphores empty, full and mutex are defined with respective initial values of 0, N and 1. Semaphore empty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore full denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by P, Q, R, and S, in the code below can be assigned either empty or full. The valid semaphore operations are: wait() and signal(). Which one of the following assignments to P, Q, R and S will yield the correct solution?

Producer:                     Consumer:

do{                           do{
    wait(P);                      wait(R);
    wait(mutex);                  wait(mutex);
    //Add item to buffer          //Consume item from buffer
    signal(mutex);                signal(mutex);
    signal(Q);                    signal(S);
}while(1);                    }while(1);
  1. (A)P: full, Q: full, R: empty, S: empty
  2. (B)P: empty, Q: empty, R: full, S: full
  3. (C)P: full, Q: empty, R: empty, S: full
  4. (D)P: empty, Q: full, R: full, S: empty
Answer: C - show solution

Here the names are swapped from the textbook: full (initial N) counts free slots and empty (initial 0) counts filled slots. The producer must wait for a free slot, wait(full), so P = full, and after adding announce a filled slot, signal(empty), so Q = empty. The consumer waits for a filled slot, wait(empty), so R = empty, and then frees a slot, signal(full), so S = full. Answer: (C).

Concept: Bounded-buffer pattern: each side waits on the counter of what it consumes and signals the counter of what it produces. The trap is going by the usual names; read the initial values and definitions given in the question.

GATE 2018 · Q63NAT2 marks · no negative· Moderate

Consider a storage disk with 4 platters (numbered as 0, 1, 2 and 3), 200 cylinders (numbered as 0, 1, ..., 199), and 256 sectors per track (numbered as 0, 1, ..., 255). The following 6 disk requests of the form [sector number, cylinder number, platter number] are received by the disk controller at the same time: [120, 72, 2], [180, 134, 1], [60, 20, 0], [212, 86, 3], [56, 116, 2], [118, 16, 1] Currently the head is positioned at sector number 100 of cylinder 80, and is moving towards higher cylinder numbers. The average power dissipation in moving the head over 100 cylinders is 20 milliwatts and for reversing the direction of the head movement once is 15 milliwatts. Power dissipation associated with rotational latency and switching of head between different platters is negligible. The total power consumption in milliwatts to satisfy all of the above disk requests using the Shortest Seek Time First disk scheduling algorithm is _______.

Answer: 85 - show solution

Cylinders requested: 72, 134, 20, 86, 116, 16. SSTF from 80: 86 (6), then 72 (14), then 116 (44, closer than 20 at 52), then 134 (18), then 20 (114), then 16 (4). Total movement = 6 + 14 + 44 + 18 + 114 + 4 = 200 cylinders, costing 200/100 × 20 = 40 mW. Direction: up to 86 (already moving up), down to 72 (reversal 1), up to 116 and 134 (reversal 2), down to 20 and 16 (reversal 3). Reversals cost 3 × 15 = 45 mW. Total = 40 + 45 = 85. Answer: 85.

Concept: SSTF picks the nearest pending cylinder each time; sector and platter numbers are distractors here. The trap is miscounting reversals: the initial move to 86 continues the current upward direction, so it is not a reversal.

GATE 2016 Set1 · Q30MCQ1 mark · -1/3· Easy

Consider an arbitrary set of CPU-bound processes with unequal CPU burst lengths submitted at the same time to a computer system. Which one of the following process scheduling algorithms would minimize the average waiting time in the ready queue?

  1. (A)Shortest remaining time first
  2. (B)Round-robin with time quantum less than the shortest CPU burst
  3. (C)Uniform random
  4. (D)Highest priority first with priority proportional to CPU burst length
Answer: A - show solution

When all processes arrive together, running them in increasing order of burst length (SJF) minimises the average waiting time, by an exchange argument. With simultaneous arrival, SRTF behaves exactly as SJF. Round-robin interleaves jobs and delays all of them; random order is not optimal; priority proportional to burst length runs the longest first, the worst order. Answer: (A).

Concept: SJF/SRTF is optimal for average waiting time. The trap is option (D), whose wording sounds like SJF but actually favours long bursts.

GATE 2016 Set1 · Q57NAT2 marks · no negative· Easy

Consider a computer system with 40-bit virtual addressing and page size of sixteen kilobytes. If the computer system has a one-level page table per process and each page table entry requires 48 bits, then the size of the per-process page table is ________ megabytes.

Answer: 384 - show solution

Page size = 16 KB = 2¹⁴ bytes. Number of pages = 2⁴⁰ / 2¹⁴ = 2²⁶ entries. Each entry is 48 bits = 6 bytes. Table size = 2²⁶ × 6 bytes = 6 × 64 MB = 384 MB. Answer: 384.

Concept: Page table size = number of virtual pages × entry size. The trap is using 48 as bytes or forgetting to convert bits to bytes.

GATE 2016 Set1 · Q58NAT2 marks · no negative· Easy

Consider a disk queue with requests for I/O to blocks on cylinders 47, 38, 121, 191, 87, 11, 92, 10. The C-LOOK scheduling algorithm is used. The head is initially at cylinder number 63, moving towards larger cylinder numbers on its servicing pass. The cylinders are numbered from 0 to 199. The total head movement (in number of cylinders) incurred while servicing these requests is ________.

Answer: 346 - show solution

C-LOOK services requests upward from 63: 87, 92, 121, 191. Movement 191 - 63 = 128. It then jumps to the lowest pending request, 10: movement 191 - 10 = 181. It then services upward: 11, 38, 47. Movement 47 - 10 = 37. Total = 128 + 181 + 37 = 346. Answer: 346.

Concept: C-LOOK reverses only as far as the last request and jumps to the lowest pending one; the jump is counted as head movement here. The trap is going to cylinder 199 or 0 (C-SCAN) or skipping the jump distance.

GATE 2016 Set1 · Q59NAT2 marks · no negative· Hard

Consider a computer system with ten physical page frames. The system is provided with an access sequence (a₁, a₂, ..., a₂₀, a₁, a₂, ..., a₂₀), where each aᵢ is a distinct virtual page number. The difference in the number of page faults between the last-in-first-out page replacement policy and the optimal page replacement policy is ________.

Answer: 1 - show solution

LIFO: a₁..a₁₀ fill the frames (10 faults). a₁₁..a₂₀ each replace the most recently loaded page (10 faults), leaving a₁..a₉ fixed plus a₂₀. Second pass: a₁..a₉ hit; a₁₀..a₂₀ are 11 faults. Total 31. Optimal: first pass 20 faults; for a₁₁ onward it evicts the page used farthest ahead, which keeps a₁..a₉ plus the latest page, ending with {a₁..a₉, a₂₀}. Second pass: a₁..a₉ hit; a₁₀..a₁₉ fault (10), each evicting a dead page, and a₂₀ is still resident, a hit. Total 30. Difference = 31 - 30 = 1. Answer: 1.

Concept: Simulating LIFO and OPT on a cyclic reference string. The trap is assuming LIFO is far worse; both keep a₁..a₉ resident, and they differ only on a₂₀ in the second pass.

GATE 2016 Set1 · Q60MCQ2 marks · -2/3· Hard

Consider the following proposed solution for the critical section problem. There are n processes: P₀ ... Pₙ₋₁. In the code, function pmax returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero. Which one of the following is TRUE about the above solution?

Code for Pi:
do {
    c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;
    for every j ≠ i in {0,...,n-1} {
        while (c[j]);
        while (t[j] != 0 && t[j]<=t[i]);
    }
    Critical Section;
    t[i]=0;
    Remainder Section;
} while (true);
  1. (A)At most one process can be in the critical section at any time
  2. (B)The bounded wait condition is satisfied
  3. (C)The progress condition is satisfied
  4. (D)It cannot cause a deadlock
Answer: A - show solution

This is Lamport's bakery algorithm without the tie-break on process id. The c[j] wait ensures Pi sees Pj's final ticket. Pi enters only after every other process j has t[j] = 0 or t[j] > t[i]; two processes cannot both see the other's ticket as strictly larger, so mutual exclusion holds: (A) is true. But two processes can compute pmax concurrently and receive the same ticket. Then each sees t[j] <= t[i] and waits for the other forever: a deadlock. So (D) is false, and progress (C) and bounded waiting (B) fail. Answer: (A).

Concept: The bakery algorithm needs the (ticket, id) tie-break; without it equal tickets deadlock, but safety still holds. The trap is assuming it is a correct bakery algorithm and picking (D).

GATE 2016 Set2 · Q30MCQ1 mark · -1/3· Easy

In which one of the following page replacement algorithms it is possible for the page fault rate to increase even when the number of allocated frames increases?

  1. (A)LRU (Least Recently Used)
  2. (B)OPT (Optimal Page Replacement)
  3. (C)MRU (Most Recently Used)
  4. (D)FIFO (First In First Out)
Answer: D - show solution

LRU and OPT are stack algorithms: the pages held with k frames are always a subset of those held with k + 1 frames, so faults never increase with more frames. FIFO is not a stack algorithm and shows Belady's anomaly, e.g. reference string 1,2,3,4,1,2,5,1,2,3,4,5 gives 9 faults with 3 frames and 10 with 4. Answer: (D) FIFO.

Concept: Belady's anomaly affects FIFO, not stack algorithms such as LRU and OPT.

GATE 2016 Set2 · Q57NAT2 marks · no negative· Moderate

Consider the following processes, with the arrival time and the length of the CPU burst given in milliseconds. The scheduling algorithm used is preemptive shortest remaining-time first. Process Arrival Time Burst Time P1 0 10 P2 3 6 P3 7 1 P4 8 3 The average turn around time of these processes is ______ milliseconds.

Answer: 8.2 to 8.3 - show solution

0-3: P1 runs (remaining 7). At 3, P2 (6) < 7, so P2 runs 3-7 (remaining 2). At 7, P3 (1) < 2, P3 runs 7-8 and finishes. At 8, remaining: P1 7, P2 2, P4 3; P2 runs 8-10 and finishes. P4 runs 10-13. P1 runs 13-20. Turnaround: P1 20 - 0 = 20, P2 10 - 3 = 7, P3 8 - 7 = 1, P4 13 - 8 = 5. Average = 33/4 = 8.25. Answer: 8.25 (accepted range 8.2 to 8.3).

Concept: SRTF re-evaluates at every arrival using remaining time, not original burst. Turnaround = completion - arrival. Using burst instead of remaining time at t = 7 is the trap.

GATE 2016 Set2 · Q58MCQ2 marks · -2/3· Easy

Consider the following two-process synchronization solution. The shared variable turn is initialized to zero. Which one of the following is TRUE?

Process 0                          Process 1
---------                          ----------
Entry: loop while (turn == 1);     Entry: loop while (turn == 0);
  (critical section)                 (critical section)
Exit:  turn = 1;                   Exit:  turn = 0;
  1. (A)This is a correct two-process synchronization solution.
  2. (B)This solution violates mutual exclusion requirement.
  3. (C)This solution violates progress requirement.
  4. (D)This solution violates bounded wait requirement.
Answer: C - show solution

Mutual exclusion holds: turn is either 0 or 1, letting only one process in. But the processes must strictly alternate. If turn = 0 and P0 does not want to enter, P1 is blocked even though the critical section is free; the decision depends on a process outside its critical section. That violates progress. Bounded waiting holds, since each waits at most one turn of the other. Answer: (C).

Concept: Strict alternation guarantees mutual exclusion and bounded waiting but fails progress. Peterson's algorithm adds flags to fix this.

GATE 2016 Set2 · Q59NAT2 marks · no negative· Easy

Consider a non-negative counting semaphore S. The operation P(S) decrements S, and V (S) increments S. During an execution, 20 P(S) operations and 12 V (S) operations are issued in some order. The largest initial value of S for which at least one P(S) operation will remain blocked is ______.

Answer: 7 - show solution

With initial value S₀, the 12 V operations make S₀ + 12 units available in total for the 20 P operations (in the most favourable order). All P operations can complete when S₀ + 12 ≥ 20, i.e. S₀ ≥ 8. At least one P must remain blocked when S₀ + 12 < 20, i.e. S₀ ≤ 7. Largest such value: 7. Answer: 7.

Concept: Count total resource supply against demand: initial value plus V operations versus P operations. Answering 8 confuses the threshold at which all P operations succeed.

GATE 2016 Set2 · Q60NAT2 marks · no negative· Moderate

A file system uses an in-memory cache to cache disk blocks. The miss rate of the cache is shown in the figure. The latency to read a block from the cache is 1 ms and to read a block from the disk is 10 ms. Assume that the cost of checking whether a block exists in the cache is negligible. Available cache sizes are in multiples of 10 MB. Miss rate from the figure: Cache size (MB): 10 20 30 40 50 60 70 80 Miss rate (%): 80 60 40 35 30 25 20 15 The smallest cache size required to ensure an average read latency of less than 6 ms is ______ MB.

Answer: 30 - show solution

Average latency = (1 - m) × 1 + m × 10 = 1 + 9m. Need 1 + 9m < 6, so m < 5/9 ≈ 55.6%. At 20 MB m = 60% gives 6.4 ms (too slow); at 30 MB m = 40% gives 4.6 ms. Even the alternative model (miss costs 1 + 10 ms, latency 1 + 10m) needs m < 50%, again first met at 30 MB. Answer: 30.

Concept: Effective access time with hits and misses, read off a miss-rate curve. Both common latency models give the same cache size here.

GATE 2014 Set1 · Q29NAT1 mark · no negative· Easy

Suppose a disk has 201 cylinders, numbered from 0 to 200. At some time the disk arm is at cylinder 100, and there is a queue of disk access requests for cylinders 30, 85, 90, 100, 105, 110, 135 and 145. If Shortest-Seek Time First (SSTF) is being used for scheduling the disk access, the request for cylinder 90 is serviced after servicing ____________ number of requests.

Answer: 3 - show solution

SSTF always picks the pending request nearest the current head position. At 100: request 100 is at distance 0 - serve it (1). At 100: 105 (5) vs 90 (10) - serve 105 (2). At 105: 110 (5) vs 90 (15) - serve 110 (3). At 110: 90 (20) vs 135 (25) - serve 90. So 90 is serviced after 3 requests. Answer: 3.

Concept: Greedy nearest-request scheduling. The trap is skipping the request at cylinder 100 itself, which is at distance 0 and is served first, giving 2 instead of 3.

GATE 2014 Set3 · Q41NAT2 marks · no negative· Easy

A system contains three programs and each requires three tape units for its operation. The minimum number of tape units which the system must have such that deadlocks never arise is _________.

Answer: 7 - show solution

Worst case: each program holds one fewer unit than it needs, i.e. 2 units each, and waits for one more. With 3 × 2 = 6 units that state is a deadlock. With one more unit (7), at least one program can get its third unit, finish and release its units, so the others can proceed. Minimum = 3 × (3 - 1) + 1 = 7. Answer: 7.

Concept: Deadlock-free resource count: Σ(maxᵢ - 1) + 1. The trap is answering 9 (enough for all at once) or 6.

GATE 2014 Set3 · Q42NAT2 marks · no negative· Moderate

An operating system uses shortest remaining time first scheduling algorithm for pre-emptive scheduling of processes. Consider the following set of processes with their arrival times and CPU burst times (in milliseconds): Process Arrival Time Burst Time P1 0 12 P2 2 4 P3 3 6 P4 8 5 The average waiting time (in milliseconds) of the processes is _________.

Answer: 5.5 - show solution

Timeline: 0-2 P1 (remaining 10). At 2, P2 (4) preempts. 2-6 P2 completes. At 6, P3 (6) is shortest. At 8, P4 arrives with 5 but P3 has 4 left, so P3 continues: 6-12 P3 completes. 12-17 P4. 17-27 P1. Waiting = completion - arrival - burst: P1 27 - 0 - 12 = 15, P2 6 - 2 - 4 = 0, P3 12 - 3 - 6 = 3, P4 17 - 8 - 5 = 4. Average = 22 / 4 = 5.5. Answer: 5.5.

Concept: SRTF compares the newcomer's burst with the running process's remaining time. The trap is preempting P3 at time 8 by comparing P4's 5 with P3's original 6.

GATE 2014 Set3 · Q43NAT2 marks · no negative· Easy

Consider a paging hardware with a TLB. Assume that the entire page table and all the pages are in the physical memory. It takes 10 milliseconds to search the TLB and 80 milliseconds to access the physical memory. If the TLB hit ratio is 0.6, the effective memory access time (in milliseconds) is _________.

Answer: 122 - show solution

TLB hit: TLB search + one memory access = 10 + 80 = 90. TLB miss: TLB search + page table access + memory access = 10 + 80 + 80 = 170. EMAT = 0.6 × 90 + 0.4 × 170 = 54 + 68 = 122. Answer: 122.

Concept: Effective access time with a TLB and a single-level page table. The trap is omitting the TLB search time on a miss, which gives 118.