OS GATE Practice Set

Mixed GATE-style questions on processes, scheduling, synchronization, deadlocks, memory, file systems and disks.

These questions mix every lesson in the Operating Systems track, in the GATE formats (MCQ, MSQ, NAT). Work each one on paper first, writing out Gantt charts, frame contents or head movements, before checking. Every numerical answer on this page is recomputed by a program when the site is built.

Processes and scheduling

GATE-styleNAT · numerical answer

[fork] How many processes in total (including the original) exist after this code runs, assuming no fork fails?

fork(); if (fork() == 0) fork();

Show answer and explanationAnswer: 6

After the first fork there are 2 processes. Each of them executes the second fork and becomes a parent and a child; only the child (for which fork returned 0) forks again. So each of the 2 processes turns into 3, giving 6 processes.

GATE-styleNAT · numerical answer

[Round Robin] Processes P1, P2 and P3 all arrive at time 0, in that order, with bursts 5, 3 and 1. With Round Robin and quantum 2 (ignoring context-switch time), what is the completion time of P1?

Show answer and explanationAnswer: 9

P1 runs 0–2, P2 2–4, P3 4–5 (done), P1 5–7, P2 7–8 (done), P1 8–9 (done). P1 completes at time 9.

GATE-styleNAT · numerical answer

[SJF] Five jobs arrive at time 0 with bursts 6, 2, 8, 3 and 4. What is the average waiting time under non-preemptive SJF?

Show answer and explanationAnswer: 6.2

SJF runs the jobs in order of burst: 2, 3, 4, 6, 8. Each waits for all the shorter jobs: 0, 2, 2 + 3 = 5, 5 + 4 = 9 and 9 + 6 = 15. The total is 31, so the average is 31 / 5 = 6.2.

Synchronization and deadlocks

GATE-styleMCQ · one correct answer

[Semaphores] Binary semaphores S and T both start at 1. Process A runs wait(S); wait(T); ... signal(T); signal(S); and process B runs wait(T); wait(S); ... signal(S); signal(T);. What can happen?

Show answer and explanationAnswer: B

If A takes S and B takes T before either takes its second semaphore, A waits for T (held by B) and B waits for S (held by A): a circular wait, so a deadlock. Acquiring S and T in the same order in both processes removes it.

GATE-styleNAT · numerical answer

[Semaphores] A counting semaphore starts at 3. Eight wait (P) and four signal (V) operations are then performed. Assuming a blocked process counts as one negative unit of the semaphore value, how many processes are blocked at the end?

Show answer and explanationAnswer: 1

The final value is 3 − 8 + 4 = −1, whatever the order of operations. A value of −1 means one process is waiting on the semaphore.

GATE-styleMCQ · one correct answer

[Deadlock] Three processes share 5 identical tape drives, and each process may need up to 3 drives. Which statement is true?

Show answer and explanationAnswer: B

The processes could hold 2, 2 and 1 drives: all 5 are allocated, no drive is free, and every process still needs more, so all three wait forever. Deadlock is ruled out only with at least n(k − 1) + 1 = 3 × 2 + 1 = 7 drives.

GATE-styleMSQ · one or more correct answers

[Deadlock] Which conditions must all hold for a deadlock to occur? (Select all that apply.)

Show answer and explanationAnswer: A, B, C

The four necessary conditions are mutual exclusion, hold and wait, no preemption and circular wait. Allowing preemption breaks one of the conditions.

Memory

GATE-styleNAT · numerical answer

[Paging] Pages are 1 KB (1024 bytes) and the page table maps page 0 → frame 3, page 1 → frame 7, page 2 → frame 1. What physical address does logical address 2100 map to?

Show answer and explanationAnswer: 1076

2100 = 2 × 1024 + 52, so it is page 2, offset 52. Page 2 is in frame 1, so the physical address is 1 × 1024 + 52 = 1076.

GATE-styleNAT · numerical answer

[TLB] A system uses two-level paging. A TLB lookup takes 5 ns and a memory access 100 ns, and the TLB hit ratio is 95%. What is the effective memory access time in ns?

Show answer and explanationAnswer: 115

Hit: 5 + 100 = 105 ns. Miss: 5 + 100 (outer table) + 100 (inner table) + 100 (data) = 305 ns. EMAT = 0.95 × 105 + 0.05 × 305 = 99.75 + 15.25 = 115 ns.

GATE-styleNAT · numerical answer

[Page replacement] The reference string 2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2 runs with 3 initially empty frames. How many page faults does FIFO cause?

Show answer and explanationAnswer: 9

Faults happen on 2, 3, 1 (filling), 5 (evicts 2), 2 (evicts 3), 4 (evicts 1), 3 (evicts 5), 5 (evicts 2) and 2 (evicts 4). The other references (the second 2, then 5 and 2 in the middle) are hits. Total: 9.

GATE-styleNAT · numerical answer

[Page replacement] For the same string and 3 frames, how many page faults does LRU cause?

Show answer and explanationAnswer: 7

Faults on 2, 3, 1, then 5 (evicts 3, least recently used), 4 (evicts 1), 3 (evicts 2) and 2 (evicts 4). The other five references are hits, so there are 7 faults, fewer than FIFO's 9.

Storage

GATE-styleNAT · numerical answer

[Inodes] Blocks are 2 KB and block pointers are 4 bytes. An inode has 8 direct pointers, one single-indirect and one double-indirect pointer. What is the maximum file size in KB?

Show answer and explanationAnswer: 525328

One block holds 2048 / 4 = 512 pointers, so the file can have 8 + 512 + 512² = 262,664 blocks of 2 KB each: 525,328 KB.

GATE-styleNAT · numerical answer

[Disk scheduling] Cylinders are numbered 0 to 199. The head is at 60 moving towards higher numbers, and the requests are 25, 120, 75, 10, 180, 95, 40. What is the total head movement with SCAN (the head goes to the end of the disk before reversing)?

Show answer and explanationAnswer: 328

The head moves up from 60, serving 75, 95, 120 and 180, continues to the end at 199 (139 cylinders in total), then reverses down to 10, serving 40, 25 and 10 (189 cylinders). Total = 328.

GATE-styleNAT · numerical answer

[Disk] What is the average rotational latency, in ms, of a disk spinning at 7500 RPM?

Show answer and explanationAnswer: 4

One rotation takes 60 / 7500 s = 8 ms, and on average the sector is half a rotation away: 4 ms.