AUTHENTIC GATE CS ARCHIVE · 1998–2024

Previous Year Questions (PYQs)

Authentic examination questions with verified official answer keys, step-by-step mathematical derivations, formula references, and critical trap warnings.

SUBJECT:Operating Systems (15 PYQs)DBMS (Coming Soon)Computer Networks (Coming Soon)Algorithms (Coming Soon)

Operating Systems · Authentic GATE CS Archive

15 Verified Questions with Solutions
GATE CS 2014· 1 Mark
OS Foundations & Kernel Architecture·Why Operating Systems Exist: The Dual Role →
Tested Principle: Kernel = Minimal set of software managing hardware resources.

Which of the following is/are NOT the primary responsibility of an operating system kernel? (P) Compiling high-level C programs (Q) Allocating physical frames to virtual memory pages (R) Scheduling threads on available CPU cores (S) Resolving hardware interrupt requests

(A)P only
(B)Q and R only
(C)P and S only
(D)Q only
Official Answer: A. P onlyStep-by-Step Derivation

Compilers (such as GCC or Clang) are user-level application programs and utility software, completely distinct from the OS kernel. Memory management (Q), CPU scheduling (R), and interrupt handling (S) are core responsibilities executed inside the OS kernel.

GATE CS 2021· 1 Mark
Tested Principle: Any instruction that can halt the CPU, alter memory mapping, disable preemption, or issue direct I/O is privileged.

Which of the following computer machine instructions MUST be privileged? (I) Set value of timer (II) Read the current clock time (III) Clear memory page tables (IV) Turn off interrupts

(A)I, II and IV only
(B)I, III and IV only
(C)II and III only
(D)I and IV only
Official Answer: B. I, III and IV onlyStep-by-Step Derivation

(I) Setting the hardware timer must be privileged so a rogue process cannot monopolize the CPU by disabling preemption. (II) Reading the time of day is a non-privileged operation (reading time harms nothing). (III) Clearing or modifying memory page tables would destroy virtual memory isolation and must be privileged. (IV) Disabling interrupts (`CLI`) prevents the OS scheduler from preempting the process and must be strictly privileged.

GATE CS 2021· 1 Mark
Processes, Threads & Concurrency·The Process Concept, Memory Layout & The PCB →
Tested Principle: Thread private state = ==purple:Stack + CPU Registers (PC, SP) + State==.

Which of the following components of a program state are NOT shared among threads of the same process? (P) Code segment (Q) Global variables (R) Stack (S) CPU Register values

(A)P and Q only
(B)R and S only
(C)Q and R only
(D)S only
Official Answer: B. R and S onlyStep-by-Step Derivation

Threads of the same process share the Text (code) segment, Data/BSS segments (global and static variables), Heap, and open file descriptors. However, each thread must independently execute its own function call sequence and instructions; therefore, each thread maintains its own ==pink:private Stack== and ==pink:private CPU Register values (including Program Counter and Stack Pointer)==.

GATE CS 2017· 1 Mark
Tested Principle: Blocked → Ready → Running (==pink:Never Blocked → Running==).

In an operating system with preemptive scheduling, which of the following process state transitions is NEVER possible?

(A)Ready → Running
(B)Running → Ready
(C)Blocked → Running
(D)Running → Blocked
Official Answer: C. Blocked → RunningStep-by-Step Derivation

When an event or I/O for a blocked (waiting) process completes, the kernel moves it to the ==yellow:READY state==. The process can only enter the RUNNING state when chosen by the CPU dispatcher from the ready queue. Direct ==pink:Blocked → Running transition violates OS scheduling invariants==.

GATE CS 2015· 1 Mark
Tested Principle: ==green:Thread switch overhead << Process switch overhead== (No MMU/page table switch).

Which of the following actions is NOT performed during a context switch between two threads of the SAME process?

(A)Saving the current thread's CPU registers
(B)Loading the next thread's Program Counter
(C)Switching the page table base pointer register
(D)Updating the current thread's state in its TCB
Official Answer: C. Switching the page table base pointer registerStep-by-Step Derivation

Threads of the same process share the same virtual address space and memory mappings. Therefore, the kernel does ==pink:NOT need to change page tables or reload the page table base register (CR3)==, and the TLB cache does not need to be invalidated. Registers (A), Program Counter (B), and Thread Control Block (TCB) state (D) are private to each thread and must be updated.

GATE CS 2014· 1 Mark

How many NEW processes are created by: fork(); fork(); fork(); in a single-process program?

(A)3
(B)6
(C)7
(D)8
Official Answer: 7Step-by-Step Derivation

After 3 consecutive forks: ==yellow:Total processes = 2^3 = 8==. ==pink:New processes = 8 - 1 = 7== (the parent process was already existing, not newly created).

[Exam Pitfall]:Question asks for NEW, not TOTAL. Total = 8, New = 7.
GATE CS 2020· 2 Marks
Tested Principle: TAT = CT - AT. Avg TAT = sum(TAT) / N.

Consider three processes P1, P2, and P3 with arrival times 0, 2, and 4 ms, and CPU burst times 4, 3, and 1 ms, respectively. If non-preemptive Shortest Job First (SJF) scheduling is used, what is the average turnaround time (in ms)?

(A)3.67 ms
(B)4.33 ms
(C)5.00 ms
(D)5.67 ms
Official Answer: A. 3.67 msStep-by-Step Derivation

1. Construct the Gantt Chart: • At t = 0 ms: Only P1 is in the ready queue. P1 executes non-preemptively from t = 0 to t = 4 ms. Completion Time ==yellow:CT(P1) = 4 ms==. • At t = 4 ms: Both P2 (arrived at t = 2, BT = 3) and P3 (arrived at t = 4, BT = 1) are present in the ready queue. Under SJF, ==green:P3 is selected because BT(P3) = 1 < BT(P2) = 3==. • P3 executes from t = 4 to t = 5 ms. Completion Time ==yellow:CT(P3) = 5 ms==. • At t = 5 ms: Only P2 remains. P2 executes from t = 5 to t = 8 ms. Completion Time ==yellow:CT(P2) = 8 ms==. 2. Calculate Turnaround Time (TAT = CT - AT): • P1: 4 - 0 = ==purple:4 ms== • P2: 8 - 2 = ==purple:6 ms== • P3: 5 - 4 = ==purple:1 ms== 3. Calculate Average Turnaround Time: Average TAT = (4 + 6 + 1) / 3 = 11 / 3 = ==yellow:3.67 ms==.

GATE CS 2019· 2 Marks
Tested Principle: Tie break rule: New arrivals enter ready queue before preempted process.

Consider three processes P1, P2, and P3 arriving at time 0, 1, and 2 with burst times 5, 3, and 1 respectively. Using Round Robin scheduling with time quantum q = 2, what is the average waiting time (in ms)?

(A)2.67 ms
(B)3.00 ms
(C)3.33 ms
(D)4.00 ms
Official Answer: A. 2.67 msStep-by-Step Derivation

Gantt Chart Execution with q = 2: 1. t=0 to 2: P1 executes (remaining BT = 3). During this time, P2 (at t=1) and P3 (at t=2) arrive. Ready queue: [P2, P3, P1]. 2. t=2 to 4: P2 executes (remaining BT = 1). Ready queue: [P3, P1, P2]. 3. t=4 to 5: P3 executes (BT=1, finishes at t=5). Ready queue: [P1, P2]. 4. t=5 to 7: P1 executes (remaining BT = 1). Ready queue: [P2, P1]. 5. t=7 to 8: P2 executes (finishes at t=8). Ready queue: [P1]. 6. t=8 to 9: P1 executes (finishes at t=9). Completion Times: P1: CT = 9, TAT = 9 - 0 = 9, WT = 9 - 5 = 4 ms. P2: CT = 8, TAT = 8 - 1 = 7, WT = 7 - 3 = 4 ms. P3: CT = 5, TAT = 5 - 2 = 3, WT = 3 - 1 = 0 ms. Total WT = 4 + 4 + 0 = 8 ms. Average WT = 8 / 3 = 2.67 ms.

GATE CS 2019· 2 Marks
Process Synchronization & Concurrency·The Critical Section Problem & Semaphores →
Tested Principle: Final S = Initial S - P + V. If S < 0, |S| processes are blocked; else 0 blocked.

A counting semaphore S is initialized to 7. Then, 20 P (wait) operations and 15 V (signal) operations are conducted on S in some arbitrary order. What is the final value of the semaphore S, and how many processes are blocked in the waiting queue?

(A)S = 2, 0 processes blocked
(B)S = 2, 2 processes blocked
(C)S = -2, 2 processes blocked
(D)S = 0, 0 processes blocked
Official Answer: A. S = 2, 0 processes blockedStep-by-Step Derivation

Formula: Final S = Initial S - (Number of P operations) + (Number of V operations) Final S = 7 - 20 + 15 = 2. Since the final value S = 2 is strictly greater than or equal to 0, no processes are blocked in the waiting queue. (If S were negative, say -2, then 2 processes would be blocked. Here S = 2, so 0 are blocked).

GATE CS 2020· 2 Marks
Deadlocks: Principles, Prevention & Avoidance·Deadlock Conditions, RAG & Banker's Algorithm →
Tested Principle: Need = Max - Allocation. Safe when Need <= Available sequentially.

A system has 4 processes P1, P2, P3, P4 and 2 resource types R1, R2. Total units of R1 = 6, R2 = 5. Allocation: P1(1,0), P2(1,1), P3(2,1), P4(0,1). Max: P1(3,2), P2(1,3), P3(3,1), P4(2,2). Is the system in a safe state, and which sequence is safe?

(A)Yes, <P3, P1, P2, P4>
(B)Yes, <P1, P3, P2, P4>
(C)No, system is deadlocked
(D)Yes, <P4, P2, P3, P1>
Official Answer: A. Yes, <P3, P1, P2, P4>Step-by-Step Derivation

1. Total Allocated: R1 = 1+1+2+0 = 4; R2 = 0+1+1+1 = 3. 2. Available = Total - Allocated = (6-4, 5-3) = (2, 2). 3. Need Matrix (Max - Alloc): P1: (3-1, 2-0) = (2, 2) P2: (1-1, 3-1) = (0, 2) P3: (3-2, 1-1) = (1, 0) P4: (2-0, 2-1) = (2, 1) 4. Testing safe sequences: P3 Need is (1, 0) <= Avail (2, 2). P3 runs! Releases Alloc (2, 1) -> New Avail = (2+2, 2+1) = (4, 3). Next P1 Need (2, 2) <= (4, 3). P1 runs! Releases (1, 0) -> New Avail = (5, 3). Next P2 Need (0, 2) <= (5, 3). P2 runs! Releases (1, 1) -> New Avail = (6, 4). Next P4 runs! All finish. Safe sequence: <P3, P1, P2, P4>.

GATE CS 2022· 2 Marks
Main Memory Management & Paging·Paging, Multi-Level Page Tables & The TLB →
Tested Principle: Two-level EMAT = h*(t_tlb + t_m) + (1-h)*(t_tlb + 2*t_m + t_m).

Consider a system with a two-level paging scheme. The TLB search time is 20 ns and main memory access time is 100 ns. The TLB hit ratio is 80%. What is the effective memory access time (in ns)?

(A)140 ns
(B)160 ns
(C)180 ns
(D)220 ns
Official Answer: B. 160 nsStep-by-Step Derivation

Assuming sequential TLB lookup and two page-table memory accesses on a miss: hit = 20 + 100 = 120 ns; miss = 20 + 2(100) + 100 = 320 ns; EMAT = 0.80(120) + 0.20(320) = 160 ns. A different answer requires a different timing convention, which must be stated and sourced.

GATE CS 2017· 2 Marks
Tested Principle: Stack Algorithms: M(n) ⊆ M(n+1) at all times t. LRU, LFU, and Optimal are immune to Belady's anomaly.

Consider the page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6. Which of the following page replacement algorithms does NOT suffer from Belady's anomaly?

(A)FIFO
(B)LRU
(C)Second Chance
(D)Random
Official Answer: B. LRUStep-by-Step Derivation

Belady's Anomaly is the phenomenon where increasing the number of allocated page frames results in an INCREASE in the total number of page faults. Mattson et al. (1970) proved that 'Stack Algorithms' (algorithms where the set of pages in memory for n frames is always a strict subset of pages in memory for n + 1 frames: M(n) ⊆ M(n + 1)) can NEVER suffer from Belady's anomaly. Both LRU and Optimal are stack algorithms and therefore never suffer from Belady's anomaly. FIFO, Second Chance, and Random do not satisfy the stack property and are susceptible to Belady's anomaly.

GATE CS 2015· 2 Marks
Tested Principle: EMAT = (1 - p) * t_m + p * S.

In a computer system with demand paging, memory access time is 200 ns and page fault service time is 10 ms. If the page fault rate is 1 out of 10,000 memory references, what is the Effective Memory Access Time (in ns)?

(A)1198 ns
(B)1200 ns
(C)1000 ns
(D)800 ns
Official Answer: B. 1200 nsStep-by-Step Derivation

1. Given: t_m = 200 ns S = 10 ms = 10,000,000 ns p = 1 / 10,000 = 0.0001 2. Formula: EMAT = (1 - p) * t_m + p * S 3. Calculation: EMAT = (1 - 0.0001) * 200 + 0.0001 * 10,000,000 EMAT = 0.9999 * 200 + 1,000 = 199.98 + 1000 ≈ 1199.98 ns ≈ 1200 ns.

GATE CS 2018· 2 Marks
File Systems & Storage Architecture·Unix Inodes & File Allocation Methods →
Tested Principle: Pointers per block = Block Size / Pointer Size. Max Size = Direct + Single*B + Double*B^2.

Consider a file system with 2 KB block size. An inode contains 10 direct, 1 single indirect, and 1 double indirect pointer. If each block pointer takes 4 bytes, what is the maximum file size (in MB, rounded to nearest integer)?

(A)256 MB
(B)513 MB
(C)1024 MB
(D)2048 MB
Official Answer: B. 513 MBStep-by-Step Derivation

1. Block Size = 2 KB = 2048 bytes. 2. Pointers per block = 2048 / 4 = 512 pointers = 2^9. 3. Direct capacity = 10 * 2 KB = 20 KB. 4. Single indirect = 512 * 2 KB = 1024 KB = 1 MB. 5. Double indirect = 512 * 512 * 2 KB = 2^9 * 2^9 * 2^11 B = 2^29 B = 512 MB. Total capacity = 20 KB + 1 MB + 512 MB = 513.02 MB ≈ 513 MB.

GATE CS 2016· 2 Marks
I/O Systems & Disk Scheduling·Disk Scheduling: SSTF, SCAN, C-SCAN & LOOK →
Tested Principle: C-SCAN: (End - Start) + (End - 0) + (Last request - 0).

Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 37, 122, 14, 124, 65, 67. The head is currently at cylinder 53 moving toward larger cylinder numbers. Total cylinders: 0 to 199. Using C-SCAN algorithm, what is the total head movement (in cylinders)?

(A)187 cylinders
(B)382 cylinders
(C)386 cylinders
(D)236 cylinders
Official Answer: B. 382 cylindersStep-by-Step Derivation

1. Head starts at 53 moving right (towards higher cylinders). 2. Requests in right direction: 65, 67, 98, 122, 124, 183. 3. C-SCAN travels all the way to disk end (cylinder 199). Movement right = 199 - 53 = 146 cylinders. 4. C-SCAN jumps from 199 to 0 (return distance = 199 cylinders). 5. From 0, it services remaining requests moving right: 14, 37 (stops at 37). Movement from 0 to 37 = 37 cylinders. Total Head Movement = (199 - 53) + (199 - 0) + (37 - 0) = 146 + 199 + 37 = 382 cylinders.