GATE CS Operating Systems PYQ with Solutions

Also searched as: GATE OS PYQ · GATE Operating System PYQ

All 51 Operating Systems questions from every GATE Computer Science (CS/CSE) paper from 2021 to 2026, both sets where there were two, with the official answer key and a step-by-step solution. Operating Systems carries about 8.2 marks per paper on average. Questions are grouped chapter-wise, newest paper first.

Operating Systems — average marks per paper
202620252024202320222021
8.57.599106.5

Operating Systems: Memory Management — GATE CS PYQ (16)

  1. GATE CS 2026 Set 1 · Q54Operating Systemsmsq2 marks
    Consider a system that has a cache memory unit and a memory management unit (MMU). The address input to the cache memory is a physical address. The MMU has a translation lookaside buffer (TLB). Assume that when a page is evicted from the main memory, the corresponding blocks in the cache are marked as invalid. For a given memory reference, which of the following sequences of events can NEVER happen?
    • A.
      TLB miss, Page table hit, Cache hit
    • B.
      TLB hit, Page table miss, Cache hit
      ✓
    • C.
      TLB miss, Page table miss, Cache hit
      ✓
    • D.
      TLB miss, Page table miss, Cache miss

    Answer: B, C

    Solution

    Answer: B, C • (A) Possible: the translation is found in the page table and the block is in the cache. • (B) Never: a TLB hit means the page table is not consulted, so there can be no page-table miss. • (C) Never: a page-table miss is a page fault, so the page is not in RAM, and its cache blocks were invalidated when it was evicted. It cannot be a cache hit. • (D) Possible: an ordinary page fault.
    Open GATE CS 2026 Set 1 Q54 · discuss this question →
  2. GATE CS 2026 Set 2 · Q54Operating Systemsnat2 marks
    A system has a TLB with a reach of 1 MB (the total physical memory reachable through its entries). The paging system uses 4 KB pages. 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: , , .

    Answer: 1536

    Solution

    Number of entries . Page number bits; frame number bits. Entry size bits bytes. TLB size bytes.
    Open GATE CS 2026 Set 2 Q54 · discuss this question →
  3. GATE CS 2026 Set 2 · Q55Operating Systemsnat2 marks
    Consider contiguous allocation using a variable partitioning scheme with 8 holes of sizes 20 KB, 4 KB, 25 KB, 18 KB, 7 KB, 9 KB, 15 KB, and 12 KB (no two holes are adjacent). Two processes P1 of size 16 KB and P2 of size 9 KB arrive in that order and are allocated using best-fit. After allocating P1 and P2, the number of holes of size less than 8 KB is __________. (answer in integer) Note: .

    Answer: 3

    Solution

    Best-fit chooses the smallest hole that fits. - P1 (16 KB): smallest hole is 18 KB → leaves a 2 KB hole. - P2 (9 KB): smallest hole is the 9 KB hole → leaves 0 (hole consumed). Resulting holes: 20, 4, 25, 2, 7, 15, 12 KB. Those KB are → .
    Open GATE CS 2026 Set 2 Q55 · discuss this question →
  4. GATE CS 2025 Set 1 · Q14Operating Systemsmcq1 mark
    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?
    • A.
      ✓
    • B.
    • C.
    • D.

    Answer: A

    Solution

    Answer: (A) Page size bytes, so the page offset is bits. With a -bit logical address, the page-number field is bits. The number of page-table entries equals the number of pages in the logical address space:
    (The physical address width determines frame-number size, not the number of page-table entries.)
    Open GATE CS 2025 Set 1 Q14 · discuss this question →
  5. GATE CS 2025 Set 1 · Q54Operating Systemsnat2 marks
    In optimal page replacement, all future references are known. A modification: the OS correctly predicts only the next 4 page references (including the current one) at the time of allocating a frame. A process accesses pages in order:
    With three frames initially empty, the number of page faults during execution is ________. (Answer in integer)

    Answer: 6

    Solution

    Answer: 6 Three frames, evict the page whose next use within the 4-reference window is farthest (or not used in the window):
    ref | frames after | fault? (eviction)
     1  | 1            | fault
     3  | 1 3          | fault
     2  | 1 3 2        | fault
     4  | 3 2 4        | fault  (window 4,2,3,1: 1 used farthest -> evict 1)
     2  | 3 2 4        | hit
     3  | 3 2 4        | hit
     1  | 2 4 1        | fault  (window 1,2,4,3: 3 farthest -> evict 3)
     2  | 2 4 1        | hit
     4  | 2 4 1        | hit
     3  | 4 1 3        | fault  (window 3,1,4: 2 not used -> evict 2)
     1  | 4 1 3        | hit
     4  | 4 1 3        | hit
    Total page faults .
    Open GATE CS 2025 Set 1 Q54 · discuss this question →
  6. GATE CS 2025 Set 2 · Q47Operating Systemsmsq2 marks
    A demand-paging system with three frames uses the reference string 1 2 3 4 5 4 1 6 4 5 1 3 2. The given frame-content table shows which references cause replacements (the *-marked ones). Which one or more of the following could be the page replacement policy in use?
    • A.
      Least Recently Used page replacement policy
    • B.
      Least Frequently Used page replacement policy
    • C.
      Most Frequently Used page replacement policy
    • D.
      Optimal page replacement policy
      ✓

    Answer: D

    Solution

    Answer: (D) Optimal page replacement policy Simulate the given string and compare the eviction choices with the table's *-marked faults. At the distinguishing replacements (e.g. the eviction made when page 6 is brought in, and later when 3 and 2 are brought in), the victim chosen is the page whose next use is farthest in the future — the hallmark of the Optimal policy. LRU, LFU and MFU each pick a different victim at one or more of these steps, producing a different frame table. Only the Optimal policy reproduces the given contents.
    Open GATE CS 2025 Set 2 Q47 · discuss this question →
  7. GATE CS 2025 Set 2 · Q58Operating Systemsnat2 marks
    A system has a -byte logical address space and uses two-level hierarchical paging with page size 4096 bytes. A logical address is split into a -bit outer-page-table index, an offset within the inner-page-table page, and an offset within the desired page. Each inner-page-table entry is 8 bytes. All pages are the same size. The value of is ___________. (Answer in integer)

    Answer: 11

    Solution

    Answer: 11 Page size → page offset bits. Inner page table fits in one page: entries per page → inner index bits. Outer index bits.
    Open GATE CS 2025 Set 2 Q58 · discuss this question →
  8. GATE CS 2024 Set 1 · Q62Operating Systemsnat2 marks
    Page size 2 KB, both physical and virtual addresses start from 0. Pages 0,1,2,3 are in frames 1,3,2,0 respectively. The physical address for virtual address 2500 is _________

    Answer: 6596

    Solution

    Answer: 6596 Page size . Virtual address : page , offset . Page 1 is in frame 3. Physical address
    Open GATE CS 2024 Set 1 Q62 · discuss this question →
  9. GATE CS 2024 Set 2 · Q24Operating Systemsmsq1 mark
    Which tasks is/are the responsibility of the MMU in paging-based memory management?
    • A.
      Allocate a new page table for a newly created process
    • B.
      Translate a virtual address to a physical address using the page table
      ✓
    • C.
      Raise a trap when a virtual address is not found in the page table
      ✓
    • D.
      Raise a trap when writing to a read-only page
      ✓

    Answer: B, C, D

    Solution

    Answer: (B), (C) and (D) The MMU (hardware) translates virtual->physical addresses using the page table (B), and raises faults/traps on invalid translations (page fault) (C) and on permission violations like writing a read-only page (D). Allocating a new page table (A) is done by the OS, not the MMU.
    Open GATE CS 2024 Set 2 Q24 · discuss this question →
  10. GATE CS 2024 Set 2 · Q64Operating Systemsnat2 marks
    32-bit system, 4 KB pages, 4-byte PTEs, 2-level page table (outer directory + inner tables), demand-paged inner tables (allocated only if they hold a valid PTE). A process accesses 2000 unique pages. X = min, Y = max number of pages across the two page-table levels. X+Y is ________

    Answer: 1028

    Solution

    Answer: 1028 Page offset bits; VPN bits split . An inner page table holds entries page. Outer directory is always 1 page. - Minimum: pack 2000 valid entries into as few inner tables as possible: inner tables -> . - Maximum: spread the 2000 pages so as many inner tables as possible each hold entry; there are only possible inner tables, and , so all are used -> .
    Open GATE CS 2024 Set 2 Q64 · discuss this question →
  11. GATE CS 2023 · Q57Operating Systemsnat2 marks
    int D[128][128] is row-major; each frame holds 512 elements; 30 frames; LRU. The code does for i: for j: D[j][i]*=10 (column-major access). The number of page faults is __________

    Answer: 4096

    Solution

    Answer: 4096 has elements, per frame, so pages; each page holds 4 full rows (since a row is 128 elements, rows per page). The access pattern D[j][i] sweeps a whole column (all 128 rows) for each , touching all 32 pages each time. With only 30 frames (LRU), every access to a page that was evicted faults. The total works out to page faults.
    Open GATE CS 2023 Q57 · discuss this question →
  12. GATE CS 2023 · Q58Operating Systemsnat2 marks
    57-bit virtual addressing, multi-level page tables with L levels, page size 4 KB, each PTE 8 bytes. The value of L is __________

    Answer: 5

    Solution

    Answer: 5 Page offset bits, so the VPN is bits. One page holds entries, so each level indexes 9 bits. Levels .
    Open GATE CS 2023 Q58 · discuss this question →
  13. GATE CS 2022 · Q38Operating Systemsmcq2 marks
    Which one of the following statements is FALSE?
    • A.
      The TLB performs an associative search in parallel on all valid entries using the page number.
    • B.
      If a virtual address has a TLB hit but the word is a cache miss, then the word is always in main memory.
    • C.
      The memory access time using an inverted page table is always the same for all incoming virtual addresses.
      ✓
    • D.
      In hashed page tables, if two distinct virtual addresses hash to the same value, their memory access times will not be the same.

    Answer: C

    Solution

    Answer: (C) — this is FALSE An inverted page table is searched (often via a hash chain) for the entry matching the virtual address, so the access time varies with the position in the table/chain — it is NOT always the same. (A), (B), and (D) are true statements.
    Open GATE CS 2022 Q38 · discuss this question →
  14. GATE CS 2022 · Q64Operating Systemsnat2 marks
    A demand-paging system with four frames (initially empty) and LRU, for the reference string 7,2,7,3,2,5,3,4,6,7,7,1,5,6,1, has page-fault rate (faults/accesses, one decimal) equal to __________.

    Answer: 0.6

    Solution

    Answer: 0.6 Reference string (15 accesses), 4 frames, LRU:
    7,2 -> faults ; 7 hit ; 3 -> fault ; 2 hit ; 5 -> fault (frames full)
    3 hit ; 4 -> fault (evict LRU) ; 6 -> fault ; 7 -> fault ; 7 hit ;
    1 -> fault ; 5 -> fault ; 6 hit? ... 1 hit
    Counting the faults gives 9 faults over 15 accesses: page-fault rate
    Open GATE CS 2022 Q64 · discuss this question →
  15. GATE CS 2021 Set 1 · Q21Operating Systemsmsq1 mark
    In the context of operating systems, which of the following statements is/are correct with respect to paging?
    • A.
      Paging helps solve the issue of external fragmentation.
      ✓
    • B.
      Page size has no impact on internal fragmentation.
    • C.
      Paging incurs memory overheads.
      ✓
    • D.
      Multi-level paging is necessary to support pages of different sizes.

    Answer: A, C

    Solution

    Paging eliminates external fragmentation (A, true) and needs page tables, i.e. memory overhead (C, true). Larger pages increase internal fragmentation, so (B) is false; multi-level paging reduces page-table size and is unrelated to supporting different page sizes, so (D) is false.
    Open GATE CS 2021 Set 1 Q21 · discuss this question →
  16. GATE CS 2021 Set 2 · Q58Operating Systemsnat2 marks
    Consider a three-level page table to translate a 39-bit virtual address to a physical address as shown below.
    <----------- 39-bit virtual address ----------->
    | Level 1 | Level 2 | Level 3 |   Page   |
    | offset  | offset  | offset  |  offset  |
    |  9 bits |  9 bits |  9 bits |  12 bits |
    The page size is 4KB ( bytes) and the page table entry size at every level is 8 bytes. A process is currently using 2GB ( bytes) virtual memory which is mapped to 2GB of physical memory. The minimum amount of memory required for the page table of across all levels is ______ KB.

    Answer: 4108

    Solution

    2GB bytes pages. Level-3 tables: tables, each 4KB KB. Level-2 tables: tables KB. Level-1: 1 table KB. Total KB.
    Open GATE CS 2021 Set 2 Q58 · discuss this question →

Operating Systems: Introduction & Process Management — GATE CS PYQ (9)

  1. GATE CS 2026 Set 1 · Q63Operating Systemsnat2 marks
    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.
    int main () {
       int i;
       for (i = 0; i < 3; i++){
          if (fork() == 0){
            continue;
          }
          break;
       }
       printf("Hello!");
       return 0;
    }
    The total number of times that the printf statement gets executed is ________. (answer in integer)

    Answer: 4

    Solution

    Answer: 4 After each fork(), the parent breaks out of the loop and prints. The child continues and forks again, so the processes form a chain, not a tree. Each of the 4 processes prints once, so the total is 4. (A plain fork() loop without the break would make .)
    GATE CS 2026 Set 1 Question 63 solution figure
    Open GATE CS 2026 Set 1 Q63 · discuss this question →
  2. GATE CS 2025 Set 1 · Q29Operating Systemsnat1 mark
    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

    Solution

    Answer: 21 Each I/O operation causes the process to move to the I/O queue; when the I/O completes, the process returns to the ready queue. So the process re-enters the ready queue once per I/O operation (the initial entry is excluded by the question). I/O operations here: - scanf → 1 I/O. - printf inside the loop, executed 20 times → 20 I/O. Total re-entries .
    Open GATE CS 2025 Set 1 Q29 · discuss this question →
  3. GATE CS 2024 Set 1 · Q24Operating Systemsmsq1 mark
    Which statements about threads is/are TRUE?
    • A.
      Threads can only be implemented in kernel space
    • B.
      Each thread has its own file descriptor table for open files
    • C.
      All threads of a process share a common stack
    • D.
      Threads of a process are by default not protected from each other
      ✓

    Answer: D

    Solution

    Answer: (D) Threads of a process share the same address space (code, heap, globals, and the file-descriptor table), so they are not protected from one another -> (D) true. (A) false (user-level threads exist); (B) false (fd table is shared); (C) false (each thread has its own stack).
    Open GATE CS 2024 Set 1 Q24 · discuss this question →
  4. GATE CS 2024 Set 1 · Q25Operating Systemsmsq1 mark
    Which process state transitions is/are NOT possible?
    • A.
      Running to Ready
    • B.
      Waiting to Running
      ✓
    • C.
      Ready to Waiting
      ✓
    • D.
      Running to Terminated

    Answer: B, C

    Solution

    Answer: (B) and (C) Valid transitions: Running->Ready (preemption), Running->Terminated (exit), Running->Waiting (I/O), Ready->Running (dispatch), Waiting->Ready (I/O done). - (B) Waiting->Running is impossible: a blocked process first becomes Ready, then is dispatched. - (C) Ready->Waiting is impossible: a process can only block while it is running (making a blocking call).
    Open GATE CS 2024 Set 1 Q25 · discuss this question →
  5. GATE CS 2024 Set 1 · Q57Operating Systemsnat2 marks
    int x=3; while(x>0){ fork(); printf("hello"); wait(NULL); x--; } The total number of times printf executes is _______

    Answer: 14

    Solution

    Answer: 14 Every call to fork() doubles the number of processes, and each process prints once per iteration:
    iteration 1 (x=3): 1 -> 2 processes, 2 printfs
    iteration 2 (x=2): 2 -> 4 processes, 4 printfs
    iteration 3 (x=1): 4 -> 8 processes, 8 printfs
    Total printf .
    Open GATE CS 2024 Set 1 Q57 · discuss this question →
  6. GATE CS 2024 Set 2 · Q25Operating Systemsmsq1 mark
    Which events ALWAYS trigger a context switch moving process P to a non-running state?
    • A.
      P makes a blocking disk read syscall
      ✓
    • B.
      P accesses a page in swap space (page fault)
      ✓
    • C.
      An interrupt from the disk delivering data for another process
    • D.
      A timer interrupt

    Answer: A, B

    Solution

    Answer: (A) and (B) - (A) A blocking syscall puts P into the blocked state and yields the CPU -> always a context switch. - (B) A major page fault (data in swap) blocks P while the page is fetched -> always a context switch. - (C) A disk interrupt for another process does not necessarily move P out of running. - (D) A timer interrupt does not always preempt P (only if the OS decides to reschedule).
    Open GATE CS 2024 Set 2 Q25 · discuss this question →
  7. GATE CS 2023 · Q22Operating Systemsmsq1 mark
    Which need to be saved on a context switch from one thread T1 to another thread T2 of the SAME process?
    • A.
      Page table base register
    • B.
      Stack pointer
      ✓
    • C.
      Program counter
      ✓
    • D.
      General purpose registers
      ✓

    Answer: B, C, D

    Solution

    Answer: (B), (C) and (D) Threads of the same process share the address space, so the page-table base register does NOT change -> (A) not needed. Each thread has its own execution context: stack pointer (B), program counter (C), and general-purpose registers (D) must be saved and restored.
    Open GATE CS 2023 Q22 · discuss this question →
  8. GATE CS 2023 · Q23Operating Systemsmsq1 mark
    Which guarantee a transition from user mode to kernel mode?
    • A.
      Function Call
    • B.
      malloc Call
    • C.
      Page Fault
      ✓
    • D.
      System Call
      ✓

    Answer: C, D

    Solution

    Answer: (C) and (D) A page fault is a trap handled by the kernel -> always enters kernel mode (C). A system call explicitly traps to the kernel (D). An ordinary function call stays in user mode (A); malloc is a library routine that usually runs in user space and only sometimes makes a system call, so it does not always transition (B).
    Open GATE CS 2023 Q23 · discuss this question →
  9. GATE CS 2021 Set 1 · Q24Operating Systemsmsq1 mark
    Which of the following standard C library functions will *always* invoke a system call when executed from a single-threaded process in a UNIX/Linux operating system?
    • A.
      exit
      ✓
    • B.
      malloc
    • C.
      sleep
      ✓
    • D.
      strlen

    Answer: A, C

    Solution

    exit always triggers the exit/_exit system call and sleep always invokes a kernel timer (e.g. nanosleep). malloc may satisfy a request from the existing heap without a syscall, and strlen is pure user-space computation.
    Open GATE CS 2021 Set 1 Q24 · discuss this question →

Operating Systems: CPU Scheduling — GATE CS PYQ (9)

  1. GATE CS 2026 Set 1 · Q64Operating Systemsnat2 marks
    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 = 10, 20, 30, 40, and 50 (in seconds). Similarly, a new process of type C arrives at time = 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 = 10 seconds. The average waiting time (in seconds) for the 10 processes is ___________. (rounded off to one decimal place)

    Answer: 9.5

    Solution

    Answer: 9.5 s
    Process | Arrival | Start | Waiting = Start − Arrival
    --------+---------+-------+--------------------------
    A1      | 10      | 10    | 0
    C1      | 11      | 16    | 5
    A2      | 20      | 24    | 4
    C2      | 22      | 30    | 8
    A3      | 30      | 38    | 8
    C3      | 33      | 44    | 11
    A4      | 40      | 52    | 12
    C4      | 44      | 58    | 14
    A5      | 50      | 66    | 16
    C5      | 55      | 72    | 17
            |         | Total | 95
    Average s.
    GATE CS 2026 Set 1 Question 64 solution figure
    Open GATE CS 2026 Set 1 Q64 · discuss this question →
  2. GATE CS 2026 Set 2 · Q23Operating Systemsmcq1 mark
    Which one of the following CPU scheduling algorithms cannot be preemptive?
    • A.
      Shortest Remaining Time First (SRTF) Scheduling
    • B.
      First Come First Serve (FCFS) Scheduling
      ✓
    • C.
      Round Robin Scheduling
    • D.
      Priority Scheduling

    Answer: B

    Solution

    Answer: (B) FCFS runs each process to completion in arrival order and has no mechanism to preempt the running process. SRTF is the preemptive form of SJF, Round Robin is inherently preemptive (time quantum), and Priority scheduling has a preemptive variant.
    Open GATE CS 2026 Set 2 Q23 · discuss this question →
  3. GATE CS 2025 Set 1 · Q38Operating Systemsmcq2 marks
    A computer has two processors, and . Four processes with CPU bursts of 20, 16, 25, and 10 ms, respectively, arrive at the same time and are the only processes in the system. The scheduler uses non-preemptive priority scheduling, with priorities: - : (so highest, lowest). - : (so highest, lowest). A process is scheduled on a free processor if no higher-priority process is waiting. A process can go to any free processor without violating priority rules. Ignore context-switch time. What is the average waiting time (ms)?
    • A.
      9.00
      ✓
    • B.
      8.75
    • C.
      6.50
    • D.
      7.50

    Answer: A

    Solution

    Answer: (A) 9.00 At both processors are free: - picks its highest-priority process (burst 20) → runs . - picks its highest-priority process (burst 16) → runs . At , frees. Remaining ; by 's order , so (burst 25) → runs . At , frees. Only left → (burst 10) → runs . Waiting times (start arrival): .
    Open GATE CS 2025 Set 1 Q38 · discuss this question →
  4. GATE CS 2025 Set 2 · Q26Operating Systemsmcq1 mark
    Processes arrive at times 0, 1, 2, 8 ms with execution times 10, 13, 6, 9 ms respectively. Shortest Remaining Time First (SRTF) is used. Ignore context switching. Which ONE correctly gives the average turnaround time (ms)?
    • A.
      22
    • B.
      15
    • C.
      37
    • D.
      19
      ✓

    Answer: D

    Solution

    Answer: (D) 19 SRTF timeline:
    t=0  P1 starts
    t=2  P3 arrives (6) < P1 remaining (8) -> run P3 until t=8
    t=8  P3 done; P4 arrives(9). remaining P1=8,P2=13,P4=9 -> run P1 (8) until 16
    t=16 run P4 (9) until 25
    t=25 run P2 (13) until 38
    Completion: . Turnaround completion arrival: . Average ms.
    Open GATE CS 2025 Set 2 Q26 · discuss this question →
  5. GATE CS 2024 Set 2 · Q37Operating Systemsmcq2 marks
    Processes A(0,10), B(2,6), C(4,3), D(6,7) (arrival, burst). Give the average waiting times for preemptive SRTF and non-preemptive SJF.
    • A.
      SRTF=6, NP-SJF=7
    • B.
      SRTF=6, NP-SJF=7.5
      ✓
    • C.
      SRTF=7, NP-SJF=7.5
    • D.
      SRTF=7, NP-SJF=8.5

    Answer: B

    Solution

    Answer: (B) SRTF=6, NP-SJF=7.5 SRTF timeline: A runs 0-2; B(6)<A(8) runs 2-4; C(3)<B(4) runs 4-7; B 7-11; D 11-18; A 18-26. Waiting = completion-arrival-burst: A=16,B=3,C=0,D=5 -> avg . NP-SJF: A 0-10; then ready {B,C,D}, shortest C 10-13; B 13-19; D 19-26. Waiting: A=0,B=11,C=6,D=13 -> avg .
    Open GATE CS 2024 Set 2 Q37 · discuss this question →
  6. GATE CS 2023 · Q27Operating Systemsmsq1 mark
    Which CPU scheduling algorithms can potentially cause starvation?
    • A.
      First-in First-Out
      ✓
    • B.
      Round Robin
    • C.
      Priority Scheduling
      ✓
    • D.
      Shortest Job First
      ✓

    Answer: A, C, D

    Solution

    Answer: (A), (C) and (D) (the official key accepted both {A,C,D} and {C,D}) Priority scheduling can indefinitely postpone low-priority processes (C), and Shortest Job First can starve long jobs when short jobs keep arriving (D). Round Robin is starvation-free (B). FIFO serves strictly in arrival order; GATE's key accepted answers both including and excluding (A), so the marked set is {A, C, D}.
    Open GATE CS 2023 Q27 · discuss this question →
  7. GATE CS 2022 · Q42Operating Systemsmcq2 marks
    Four processes P, Q, R, S arrive at t=0 in that order, scheduled by Round Robin with quantum 4. There is exactly one context switch S->Q, exactly one R->Q, exactly two Q->R, and no S->P. Which CPU burst times are NOT possible?
    • A.
      P = 4, Q = 10, R = 6, S = 2
    • B.
      P = 2, Q = 9, R = 5, S = 1
    • C.
      P = 4, Q = 12, R = 5, S = 4
    • D.
      P = 3, Q = 7, R = 7, S = 3
      ✓

    Answer: D

    Solution

    Answer: (D) P = 3, Q = 7, R = 7, S = 3 Simulating Round Robin (quantum 4) for each option and checking the required context-switch pattern (exactly one S->Q, one R->Q, two Q->R, and no S->P): option (D)'s burst times produce a schedule that violates these constraints (it does not yield exactly two Q->R switches without an S->P switch), so it is NOT possible.
    Open GATE CS 2022 Q42 · discuss this question →
  8. GATE CS 2021 Set 1 · Q35Operating Systemsnat1 mark
    Three processes arrive at time zero with CPU bursts of 16, 20 and 10 milliseconds. If the scheduler has prior knowledge about the length of the CPU bursts, the minimum achievable average waiting time for these three processes in a non-preemptive scheduler (rounded to nearest integer) is ______ milliseconds.

    Answer: 12

    Solution

    Shortest-Job-First minimizes average waiting time. Order 10, 16, 20: waiting times are ; average ms.
    Open GATE CS 2021 Set 1 Q35 · discuss this question →
  9. GATE CS 2021 Set 2 · Q24Operating Systemsmsq1 mark
    Which of the following statement(s) is/are correct in the context of CPU scheduling?
    • A.
      Turnaround time includes waiting time.
      ✓
    • B.
      The goal is to only maximize CPU utilization and minimize throughput.
    • C.
      Round-robin policy can be used even when the CPU time required by each of the processes is not known apriori.
      ✓
    • D.
      Implementing preemptive scheduling needs hardware support.
      ✓

    Answer: A, C, D

    Solution

    Turnaround time = waiting + burst (+ I/O) time, so (A) is true. The goal is to maximize throughput, not minimize it, so (B) is false. Round-robin needs no prior knowledge of burst lengths (C true). Preemption relies on a timer interrupt, i.e. hardware support (D true).
    Open GATE CS 2021 Set 2 Q24 · discuss this question →

Operating Systems: Process Synchronization — GATE CS PYQ (7)

  1. GATE CS 2026 Set 2 · Q51Operating Systemsmsq2 marks
    Consider three processes P1, P2, P3 running identical code. and are binary semaphores initialized to 1 and 0; is a shared variable initialized to 0. Each line executes atomically.
    Wait(A);
    Print(*);
    X = X+1;
    If (X == 2) {
       Print($);
       Signal(B);
    }
    Signal(A);
    Wait(B);
    Print(#);
    Signal(B);
    Any process may start first and context switches may occur at any time. Which of the following patterns is/are possible outcomes?
    • A.
      **$*###
      ✓
    • B.
      **$#*##
      ✓
    • C.
      **$##*#
      ✓
    • D.
      ***$###

    Answer: A, B, C

    Solution

    Answer: (A), (B), (C) Semaphore serializes the Print(*); X=X+1 section, so the three * are printed one at a time. The second process to enter the section makes and prints $ immediately after its * (and Signal(B)), so the output always begins with **$. The remaining * (third process) and the three # (released one-by-one by ) can interleave in several ways — options (A), (B), (C) are all realizable. Option (D) ***$### needs all three * before $, impossible since $ is printed right after the second *.
    Open GATE CS 2026 Set 2 Q51 · discuss this question →
  2. GATE CS 2024 Set 1 · Q40Operating Systemsmcq2 marks
    Threads T1 (a=a+1; b=b+1) and T2 (b=2*b; a=2*a), initially a=b=1, each statement atomic. Which option lists all possible (a,b) after both finish?
    • A.
      (4,4); (3,3); (4,3)
      ✓
    • B.
      (3,4); (4,3); (3,3)
    • C.
      (4,4); (4,3); (3,4)
    • D.
      (2,2); (2,3); (3,4)

    Answer: A

    Solution

    Answer: (A) (a = 4, b = 4); (a = 3, b = 3); (a = 4, b = 3) T1: a=a+1; b=b+1. T2: b=2b; a=2a. Each statement is atomic; initially a=b=1. Final depends on the order of "a=a+1" (T1) and "a=2a" (T2); final on "b=b+1" (T1) and "b=2b" (T2). - T1 fully before T2: -> (4,4). - T2 fully before T1: -> (3,3). - Interleave (b=2b, a=a+1, b=b+1, a=2a): -> (4,3). - (3,4) is NOT reachable: needs "a=2a" before "a=a+1", which forces "b=2b" before "b=b+1", giving (not 4). Reachable set = option (A).
    Open GATE CS 2024 Set 1 Q40 · discuss this question →
  3. GATE CS 2024 Set 2 · Q46Operating Systemsmsq2 marks
    T1: wait(s1); x=x+1; print(x); wait(s2); signal(s1). T2: wait(s1); x=x+1; print(x); signal(s2); signal(s1). s1=1, s2=0, x=0. Which outcomes are possible?
    • A.
      T1 first prints 1, T2 next prints 2
    • B.
      T2 first prints 1, T1 next prints 2
      ✓
    • C.
      T1 first prints 1, T2 deadlock
      ✓
    • D.
      T2 first prints 1, T1 next prints 2 (no deadlock)

    Answer: B, C

    Solution

    Answer: (B) and (C) - If T2 acquires s1 first: it prints 1, signals s2, signals s1; then T1 acquires s1, prints 2, wait(s2) succeeds (s2=1), signal(s1). Works -> (B) possible. - If T1 acquires s1 first: it prints 1, then wait(s2) blocks (s2=0) while still holding s1; T2 can never get s1 -> deadlock -> (C) possible. - (A) impossible (T1 first always deadlocks). (D) impossible (T2 first prints 1 then T1 prints 2 is exactly (B), not a new distinct option as worded — the valid non-deadlock case is (B)).
    Open GATE CS 2024 Set 2 Q46 · discuss this question →
  4. GATE CS 2023 · Q38Operating Systemsmcq2 marks
    incr/decr each do wait(s); X=X±1; signal(s). 5 threads call incr, 3 call decr, initial X=10. I-1: s binary semaphore =1. I-2: s counting semaphore =2. are final X values. Which gives the MINIMUM possible ?
    • A.
      15, 7
    • B.
      7, 7
    • C.
      12, 7
      ✓
    • D.
      12, 8

    Answer: C

    Solution

    Answer: (C) 12, 7 5 threads call incr (X+1), 3 call decr (X-1); initial X=10. - I-1 (binary semaphore = 1): mutual exclusion holds, so every update applies: (fixed; its minimum is 12). - I-2 (counting semaphore = 2): up to two threads are in the critical section at once, so increments can be lost through races. Minimizing by losing increments while keeping decrements, the smallest reachable value is . Hence .
    Open GATE CS 2023 Q38 · discuss this question →
  5. GATE CS 2022 · Q19Operating Systemsmcq1 mark
    Threads T1 (wait S3; print "C"; signal S2), T2 (wait S1; print "B"; signal S3), T3 (wait S2; print "A"; signal S1), each in a while(true) loop. Which initialization prints BCABCA...?
    • A.
      S1 = 1; S2 = 1; S3 = 1
    • B.
      S1 = 1; S2 = 1; S3 = 0
    • C.
      S1 = 1; S2 = 0; S3 = 0
      ✓
    • D.
      S1 = 0; S2 = 1; S3 = 1

    Answer: C

    Solution

    Answer: (C) S1 = 1; S2 = 0; S3 = 0 To print B first, T2 must run first, so S1=1 (and S2=S3=0 to block T3, T1 initially). T2 prints B, signals S3 -> T1 prints C, signals S2 -> T3 prints A, signals S1 -> T2 again... producing B,C,A,B,C,A,... So S1=1, S2=0, S3=0.
    Open GATE CS 2022 Q19 · discuss this question →
  6. GATE CS 2021 Set 1 · Q56Operating Systemsmsq2 marks
    Consider the following pseudocode, where S is a semaphore initialized to 5 in line#2 and counter is a shared variable initialized to 0 in line#1. Assume that the increment operation in line#7 is *not* atomic.
    1.  int counter = 0;
    2.  Semaphore S = init(5);
    3.  void parop(void)
    4.  {
    5.      wait(S);
    6.      wait(S);
    7.      counter++;
    8.      signal(S);
    9.      signal(S);
    10. }
    If five threads execute the function parop concurrently, which of the following program behavior(s) is/are possible?
    • A.
      The value of counter is 5 after all the threads successfully complete the execution of parop.
      ✓
    • B.
      The value of counter is 1 after all the threads successfully complete the execution of parop.
      ✓
    • C.
      The value of counter is 0 after all the threads successfully complete the execution of parop.
    • D.
      There is a deadlock involving all the threads.
      ✓

    Answer: A, B, D

    Solution

    Each thread does two waits. In a serialized interleaving counter reaches 5 (A). With up to two threads in the critical section and a non-atomic increment, lost updates can leave counter as low as 1 (B). If every thread completes its first wait before any does the second, all 5 units of S are taken and all block — deadlock (D). counter can never be 0 after all complete, so (C) is impossible.
    Open GATE CS 2021 Set 1 Q56 · discuss this question →
  7. GATE CS 2021 Set 2 · Q52Operating Systemsmsq2 marks
    Consider the following multi-threaded code segment (in a mix of C and pseudo-code), invoked by two processes P1 and P2, and each of the processes spawns two threads T1 and T2:
    int x = 0;   // global
    Lock L1;     // global
    main() {
        create a thread to execute foo();  // Thread T1
        create a thread to execute foo();  // Thread T2
        wait for the two threads to finish execution;
        print(x);
    }
    foo() {
        int y = 0;
        Acquire L1;
        x = x + 1;
        y = y + 1;
        Release L1;
        print(y);
    }
    Which of the following statement(s) is/are correct?
    • A.
      Both P1 and P2 will print the value of x as 2.
      ✓
    • B.
      At least one of P1 and P2 will print the value of x as 4.
    • C.
      At least one of the threads will print the value of y as 2.
    • D.
      Both T1 and T2, in both the processes, will print the value of y as 1.
      ✓

    Answer: A, D

    Solution

    Processes have separate address spaces, so each process's global x is incremented by its own two threads (under the lock) to 2 — (A) true, and (B) false (x is never shared to reach 4). y is a local variable, always ending at 1 — (D) true, (C) false.
    Open GATE CS 2021 Set 2 Q52 · discuss this question →

Operating Systems: Deadlock — GATE CS PYQ (5)

  1. GATE CS 2026 Set 1 · Q29Operating Systemsmsq1 mark
    With respect to deadlocks in an operating system, which of the following statements is/are FALSE?
    • A.
      Banker’s algorithm is used to prevent deadlocks
      ✓
    • B.
      Deadlock formation can be prevented by ensuring that the hold and wait condition is not allowed
    • C.
      An assignment edge in a resource allocation graph is marked from a process to a resource
      ✓
    • D.
      A safe state guarantees that all processes can finish without formation of a deadlock

    Answer: A, C

    Solution

    Answer: A, C (the question asks for FALSE statements) • (A) FALSE: the Banker's algorithm is deadlock avoidance, not prevention. • (B) True: breaking hold-and-wait is a prevention technique. • (C) FALSE: an assignment edge points resource → process. A request edge points process → resource. • (D) True: a safe sequence exists, by definition.
    Open GATE CS 2026 Set 1 Q29 · discuss this question →
  2. GATE CS 2026 Set 1 · Q35Operating Systemsnat1 mark
    Consider a system consisting of instances of a resource , being shared by 5 processes. Assume that each process requires a maximum of two instances of resource 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 for the system to be deadlock-free is ________. (answer in integer)

    Answer: 6

    Solution

    Answer: 6 Worst case: every process holds one instance and waits for its second. With , all 5 instances are held and everyone waits, which is a deadlock. One more instance breaks this: . Some process can then finish and release its instances.
    Open GATE CS 2026 Set 1 Q35 · discuss this question →
  3. GATE CS 2025 Set 2 · Q48Operating Systemsmsq2 marks
    are processes; are single-instance resources. Assignment edges: . Claim (wait) edges: . Which of the following statement(s) is/are CORRECT?
    • A.
      Aborting makes the system deadlock free.
    • B.
      Aborting makes the system deadlock free.
    • C.
      Aborting makes the system deadlock free.
      ✓
    • D.
      Aborting and makes the system deadlock free.
      ✓

    Answer: C, D

    Solution

    Answer: (C) and (D) Build the wait-for graph ( if waits for a resource held by ):
    P1->P2,  P2->P3,  P3->P1,  P2->P4,  P4->P2
    There are two cycles: and . - Aborting breaks only the first cycle; remains → still deadlocked. (A) wrong. - Aborting breaks only the first cycle; remains. (B) wrong. - lies on both cycles, so aborting breaks both → deadlock free. (C) correct. - Aborting (breaks cycle 1) and (breaks cycle 2) removes both cycles → deadlock free. (D) correct.
    Open GATE CS 2025 Set 2 Q48 · discuss this question →
  4. GATE CS 2022 · Q26Operating Systemsmsq1 mark
    Which statements about deadlocks are TRUE?
    • A.
      Circular wait is a necessary condition for deadlock.
      ✓
    • B.
      If each resource has more than one instance, a cycle in the wait-for graph indicates a deadlock.
    • C.
      If current allocation leads to an unsafe state, deadlock will necessarily occur.
    • D.
      If every edge in the resource-allocation graph is an assignment edge, the system is not in deadlock.
      ✓

    Answer: A, D

    Solution

    Answer: (A) and (D) - (A) Circular wait is one of the four necessary (Coffman) conditions for deadlock. True. - (D) If every edge is an assignment edge (no process is waiting/requesting), no process is blocked, so no deadlock. True. - (B) False: with multiple instances, a cycle is necessary but not sufficient for deadlock. - (C) False: an unsafe state may lead to deadlock but does not guarantee it.
    Open GATE CS 2022 Q26 · discuss this question →
  5. GATE CS 2021 Set 2 · Q53Operating Systemsmsq2 marks
    Consider a computer system with multiple shared resource types, with one instance per resource type. Each instance can be owned by only one process at a time. Owning and freeing of resources are done by holding a global lock (L). The following scheme is used to own a resource instance:
    function OwnResource(Resource R)
        Acquire lock L            // a global lock
        if R is available then
            Acquire R
            Release lock L
        else
            if R is owned by another process P then
                Terminate P, after releasing all resources owned by P
                Acquire R
                Restart P
                Release lock L
            end if
        end if
    end function
    Which of the following choice(s) about the above scheme is/are correct?
    • A.
      The scheme ensures that deadlocks will not occur.
      ✓
    • B.
      The scheme may lead to live-lock.
      ✓
    • C.
      The scheme may lead to starvation.
      ✓
    • D.
      The scheme violates the mutual exclusion property.

    Answer: A, B, C

    Solution

    Because a requester forcibly terminates the current owner, no circular wait can form, so deadlock cannot occur (A). But a repeatedly terminated-and-restarted process may keep being preempted, producing live-lock (B) and starvation (C). Resources are still acquired exclusively, so mutual exclusion is not violated (D false).
    Open GATE CS 2021 Set 2 Q53 · discuss this question →

Operating Systems: File Systems & I/O — GATE CS PYQ (5)

  1. GATE CS 2026 Set 2 · Q53Operating Systemsnat2 marks
    To keep track of free blocks in a file system, the linked list approach is used. Assume the disk size is 16 GB, block size is 2 KB, and block numbers 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. The number of blocks required to hold the free disk block numbers is __________. (answer in integer) Note: , .

    Answer: 16417

    Solution

    Total disk blocks . Usable space per list block bytes → block numbers per block. Blocks needed .
    Open GATE CS 2026 Set 2 Q53 · discuss this question →
  2. GATE CS 2025 Set 1 · Q51Operating Systemsnat2 marks
    A disk of size 512M bytes is divided into blocks of 64K bytes. A file is stored using linked allocation. Each data block reserves 4 bytes to store the pointer to the next block; the last block's link is a NULL pointer (also 4 bytes). A file of 1M bytes is stored. Assume , . The amount of space in bytes wasted due to internal fragmentation is ______. (Answer in integer)

    Answer: 65468

    Solution

    Answer: 65468 Each -byte block reserves bytes for the pointer, leaving bytes of data per block. File size bytes. Blocks needed blocks. - First 16 blocks hold bytes. - Remaining file data bytes, placed in the 17th block. Internal fragmentation is the unused data area of the last block:
    Open GATE CS 2025 Set 1 Q51 · discuss this question →
  3. GATE CS 2024 Set 1 · Q54Operating Systemsnat2 marks
    A 512 GB hard disk has 32 surfaces, 4096 sectors per track, 1024 bytes per sector. The number of cylinders is _________

    Answer: 4096

    Solution

    Answer: 4096 Bytes per track . Total bytes . Total tracks . A cylinder spans all 32 () surfaces, so
    Open GATE CS 2024 Set 1 Q54 · discuss this question →
  4. GATE CS 2022 · Q63Operating Systemsnat2 marks
    File systems A (contiguous) and B (linked) each store a 100-block file. A new block (data in memory) is inserted between the 50th and 51st block, with free blocks at the end and FCBs in memory. If are the disk accesses for A and B, then is __________.

    Answer: 153

    Solution

    Answer: 153 To insert a block between the 50th and 51st block of a 100-block file: - Contiguous (A): shift blocks 51-100 (50 blocks) one position forward — read each and write each (), plus write the new block, plus ... giving disk accesses. - Linked (B): traverse to the 50th block and relink — accesses (read the 50th block, write the new block, write the updated pointer).
    Open GATE CS 2022 Q63 · discuss this question →
  5. GATE CS 2021 Set 1 · Q25Operating Systemsmsq1 mark
    Consider a linear list based directory implementation in a file system. Each directory is a list of nodes, where each node contains the file name along with the file metadata, such as the list of pointers to the data blocks. Consider a given directory foo. Which of the following operations will necessarily require a full scan of foo for successful completion?
    • A.
      Creation of a new file in foo
      ✓
    • B.
      Deletion of an existing file from foo
    • C.
      Renaming of an existing file in foo
      ✓
    • D.
      Opening of an existing file in foo

    Answer: A, C

    Solution

    Creating a new file must confirm the name does not already exist, requiring a full scan (A). Renaming must find the file and confirm the new name is unused, requiring a full scan (C). Deleting and opening can stop as soon as the file is found, so they do not necessarily scan the whole list.
    Open GATE CS 2021 Set 1 Q25 · discuss this question →

Take a Operating Systems chapter-wise test

Pick any chapters and attempt their PYQs with a timer in the GATE interface, with instant analysis — free.

Create free account →

More GATE CS PYQ subject-wise