Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

What is a resource allocation graph? Explain the process of detecting deadlock when there is a single instance of each resource type with a suitable example.

Resource Allocation Graph (RAG)

A Resource Allocation Graph is a directed graph used to describe the state of allocation of resources to processes in a system. It is used to detect and reason about deadlocks.

Components:

  • Vertices are of two types:
    • Process nodes (P1,P2,P_1, P_2, \dots) drawn as circles.
    • Resource nodes (R1,R2,R_1, R_2, \dots) drawn as rectangles; dots inside a rectangle represent the number of instances of that resource.
  • Edges are of two types:
    • Request edge PiRjP_i \rightarrow R_j: process PiP_i has requested resource RjR_j and is waiting.
    • Assignment edge RjPiR_j \rightarrow P_i: an instance of RjR_j has been allocated to PiP_i.

Deadlock Detection with a Single Instance per Resource

When each resource type has exactly one instance, deadlock detection reduces to a simple rule:

A deadlock exists if and only if the resource allocation graph contains a cycle.

With multiple instances a cycle is only a necessary condition, but with single instances a cycle is both necessary and sufficient.

Detection algorithm: Construct a wait-for graph by removing resource nodes from the RAG and collapsing edges: if PiRjP_i \rightarrow R_j and RjPkR_j \rightarrow P_k, add an edge PiPkP_i \rightarrow P_k. Then run a cycle-detection (DFS) on the wait-for graph; any cycle indicates deadlock.

Example

Consider processes P1,P2,P3P_1, P_2, P_3 and single-instance resources R1,R2,R3R_1, R_2, R_3:

  • R1P1R_1 \rightarrow P_1 (R1 held by P1)
  • P1R2P_1 \rightarrow R_2 (P1 requests R2)
  • R2P2R_2 \rightarrow P_2 (R2 held by P2)
  • P2R3P_2 \rightarrow R_3 (P2 requests R3)
  • R3P3R_3 \rightarrow P_3 (R3 held by P3)
  • P3R1P_3 \rightarrow R_1 (P3 requests R1)

Following the edges we get the cycle:

P1R2P2R3P3R1P1P_1 \rightarrow R_2 \rightarrow P_2 \rightarrow R_3 \rightarrow P_3 \rightarrow R_1 \rightarrow P_1

Since a cycle exists and each resource has a single instance, the system is deadlocked: P1P_1 waits for R2R_2 held by P2P_2, P2P_2 waits for R3R_3 held by P3P_3, and P3P_3 waits for R1R_1 held by P1P_1 — a circular wait that can never resolve.

If instead P3P_3 had not requested R1R_1 (no edge P3R1P_3 \rightarrow R_1), the graph would be acyclic and no deadlock would exist.

deadlockresource-allocation-graph
2long10 marks

Explain the Critical Section problem. Describe Peterson's solution and the use of semaphores to achieve process synchronization.

The Critical Section Problem

A critical section is a segment of code in which a process accesses shared resources (variables, files, devices). When multiple processes run concurrently, uncontrolled access to such shared data causes race conditions. The critical-section problem is to design a protocol that processes use to cooperate, ensuring correct execution.

A correct solution must satisfy three requirements:

  1. Mutual Exclusion — at most one process executes in its critical section at a time.
  2. Progress — if no process is in its critical section, only the processes contending may decide who enters next, and this decision cannot be postponed indefinitely.
  3. Bounded Waiting — there is a bound on how many times other processes enter their critical sections after a process requests entry and before it is granted (no starvation).

The general structure of each process is:

do {
    entry section
        critical section
    exit section
        remainder section
} while (true);

Peterson's Solution

Peterson's solution is a classic software solution for two processes (P0P_0 and P1P_1). It uses two shared variables:

  • int turn; — whose turn it is to enter.
  • boolean flag[2];flag[i] is true if PiP_i wants to enter.

Code for process PiP_i (where j = 1 - i):

do {
    flag[i] = true;
    turn = j;
    while (flag[j] && turn == j);  // busy wait
        // critical section
    flag[i] = false;
        // remainder section
} while (true);

PiP_i sets its flag and politely gives the turn to PjP_j. It enters only if PjP_j does not want in (!flag[j]) or it is PiP_i's turn. This satisfies mutual exclusion, progress, and bounded waiting, but relies on busy waiting and only works for two processes.

Semaphores

A semaphore SS is an integer variable accessed only through two atomic operations:

wait(S):  while (S <= 0); S = S - 1;   // also called P()
signal(S): S = S + 1;                   // also called V()

Practical implementations avoid busy waiting by maintaining a waiting queue: wait() blocks the process when S<0S<0, and signal() wakes a blocked process.

Achieving synchronization: Initialize a semaphore mutex = 1. Each process wraps its critical section:

wait(mutex);
    // critical section
signal(mutex);
    // remainder section

This guarantees mutual exclusion for any number of processes. Counting semaphores (initialized to NN) control access to a pool of NN identical resources, while a binary semaphore (values 0/1) acts as a mutex lock.

synchronizationcritical-section
3long10 marks

Explain paging as a memory management technique. Discuss how logical addresses are translated to physical addresses using a page table and TLB.

Paging

Paging is a memory-management scheme that allows the physical address space of a process to be non-contiguous, eliminating external fragmentation and the need for compaction.

  • Physical memory is divided into fixed-size blocks called frames.
  • Logical (virtual) memory is divided into blocks of the same size called pages.
  • A typical page/frame size is a power of two (e.g., 4 KB).
  • When a process executes, its pages are loaded into any available frames; the OS keeps the page-to-frame mapping in a page table.

Logical-to-Physical Address Translation

The CPU generates a logical address split into two parts:

Logical Address=(ppage number, dpage offset)\text{Logical Address} = (\underbrace{p}_{\text{page number}},\ \underbrace{d}_{\text{page offset}})

If the logical address space is 2m2^m and the page size is 2n2^n, then the high-order mnm-n bits give the page number pp and the low-order nn bits give the offset dd.

Steps:

  1. Extract page number pp and offset dd from the logical address.
  2. Use pp as an index into the page table to obtain the frame number ff.
  3. Form the physical address as f×(page size)+df \times (\text{page size}) + d, i.e., concatenate frame number ff with offset dd.
Physical Address=(f,d)\text{Physical Address} = (f, d)

The offset dd is unchanged because pages and frames are the same size.

Translation Look-aside Buffer (TLB)

Using only a page table requires two memory accesses per reference (one to read the page table, one for the data), which is slow. A TLB is a small, fast, fully-associative hardware cache that stores recently used (page → frame) mappings.

Address translation with TLB:

  1. Present page number pp to the TLB.
  2. TLB hit: frame ff is returned immediately; combine with offset dd.
  3. TLB miss: access the page table in memory to get ff, then load that mapping into the TLB for future use.

Effective Access Time (EAT): If TLB lookup takes ϵ\epsilon, memory access takes mm, and the hit ratio is α\alpha:

EAT=α(ϵ+m)+(1α)(ϵ+2m)EAT = \alpha(\epsilon + m) + (1-\alpha)(\epsilon + 2m)

Example: with m=100m = 100 ns, ϵ=20\epsilon = 20 ns, α=0.8\alpha = 0.8:

EAT=0.8(120)+0.2(220)=96+44=140 nsEAT = 0.8(120) + 0.2(220) = 96 + 44 = 140 \text{ ns}

This is far better than the 200 ns required without a TLB on every access.

memory-managementpaging
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Distinguish between starvation and deadlock.

Deadlock and starvation are both situations where processes fail to make progress, but they differ fundamentally:

AspectDeadlockStarvation
DefinitionA set of processes are permanently blocked because each holds a resource and waits for one held by another (circular wait).A process waits indefinitely because resources are repeatedly granted to other (often higher-priority) processes.
Affected processesA group, in a circular-wait chain.Usually a single (or few) low-priority process.
Progress in systemThe involved processes make no progress at all.Other processes keep progressing; only the starved one does not.
CauseHold-and-wait + circular wait + mutual exclusion + no preemption.Biased scheduling / resource allocation policy (e.g., priority scheduling, SJF).
ResolutionWill not resolve on its own; needs prevention, avoidance, detection & recovery.Can be resolved by aging (gradually raising waiting processes' priority).
Also calledCircular wait.Indefinite blocking / lockout.

Key point: Every deadlock implies starvation for the involved processes, but starvation does not imply deadlock — a starved process may still eventually run.

deadlockstarvation
5short5 marks

Explain context switching and its overhead.

Context Switching

A context switch is the mechanism by which the CPU is switched from one process (or thread) to another. The kernel saves the state (context) of the currently running process and restores the state of the next scheduled process.

The context of a process is held in its Process Control Block (PCB) and includes:

  • Program counter and CPU registers,
  • CPU scheduling information and process state,
  • Memory-management information (page tables, base/limit registers),
  • I/O status and accounting information.

Steps: save current process state → PCB; update its PCB and queues; select next process via the scheduler; restore the next process's state from its PCB; resume execution.

Context switches occur on interrupts, system calls, time-slice expiry, or when a process blocks for I/O.

Overhead

Context switching is pure overhead — during the switch the CPU does no useful work for any user process:

  • Time spent saving/restoring registers and PCB data.
  • Cache and TLB are flushed/invalidated, so the new process suffers cache misses afterward.
  • On paged systems, memory-management structures (page tables) must be reloaded.

The cost depends on hardware support (e.g., multiple register sets reduce it). Frequent context switching (e.g., a very small time quantum in Round Robin) degrades throughput, so the quantum is chosen to keep switching overhead a small fraction of the total CPU time.

processcontext-switch
6short5 marks

What is the producer-consumer problem? Explain in brief.

Producer-Consumer (Bounded-Buffer) Problem

The producer-consumer problem is a classic synchronization problem involving two types of processes sharing a fixed-size buffer of NN slots:

  • The producer generates data items and places them into the buffer.
  • The consumer removes items from the buffer and uses them.

The challenge (synchronization conditions):

  • The producer must not add to a full buffer (wait until a slot is free).
  • The consumer must not remove from an empty buffer (wait until an item exists).
  • The producer and consumer must not access the buffer simultaneously (mutual exclusion on the shared buffer / count).

Semaphore Solution

Three semaphores are used:

  • mutex = 1 — mutual exclusion on the buffer.
  • empty = N — counts empty slots.
  • full = 0 — counts filled slots.
// Producer
wait(empty); wait(mutex);
    add item to buffer;
signal(mutex); signal(full);

// Consumer
wait(full); wait(mutex);
    remove item from buffer;
signal(mutex); signal(empty);

This ensures the producer blocks when the buffer is full and the consumer blocks when it is empty, while mutex prevents simultaneous access. It illustrates cooperation between processes that must share a bounded buffer correctly.

synchronization
7short5 marks

Explain the Dining Philosophers problem.

Dining Philosophers Problem

The Dining Philosophers problem is a classic synchronization problem that illustrates deadlock and resource-sharing issues among concurrent processes.

Setup: Five philosophers sit around a circular table. Each philosopher alternates between thinking and eating. There are five chopsticks, one between each pair of philosophers. To eat, a philosopher needs both the chopstick to their left and the one to their right. After eating, they put both chopsticks down and resume thinking.

The chopsticks are the shared resources, and each is modeled by a semaphore:

semaphore chopstick[5] = {1,1,1,1,1};

do {
    wait(chopstick[i]);             // pick up left
    wait(chopstick[(i+1) % 5]);     // pick up right
        // eat
    signal(chopstick[i]);
    signal(chopstick[(i+1) % 5]);
        // think
} while (true);

The problem: If all five philosophers simultaneously pick up their left chopstick, each then waits forever for the right chopstick held by a neighbor — a circular wait, i.e., deadlock. There is also a risk of starvation.

Solutions:

  1. Allow at most four philosophers at the table at once.
  2. A philosopher may pick up chopsticks only if both are available (pick up inside a critical section).
  3. Use asymmetry: odd philosophers pick up left-then-right, even philosophers right-then-left, breaking the circular wait.
synchronizationdeadlock
8short5 marks

What is thrashing? How can it be prevented?

Thrashing

Thrashing is a condition in a virtual-memory system where a process (or the whole system) spends more time paging (swapping pages in and out of memory) than executing. CPU utilization drops sharply because processes are constantly waiting for pages.

Cause: It occurs when a process does not have enough frames to hold its working set (the set of pages it is actively using). Each instruction may cause a page fault, evicting a page that is needed again immediately, causing another fault — a high page-fault rate.

The vicious cycle: Low CPU utilization → OS increases the degree of multiprogramming → less memory per process → more page faults → even lower CPU utilization.

Prevention / Control

  1. Working-Set Model: Track each process's working set using a window of recent references; allocate enough frames to hold it, and suspend (swap out) a process if the demand exceeds available frames.
  2. Page-Fault Frequency (PFF) control: Monitor each process's page-fault rate; if it rises above an upper bound, allocate more frames; if it falls below a lower bound, reclaim frames.
  3. Reduce the degree of multiprogramming: Swap out some processes so the rest have enough frames.
  4. Use local page-replacement so one greedy process cannot steal frames from others, and add more physical RAM.
virtual-memorythrashing
9short5 marks

Differentiate between logical and physical address space.

Logical vs Physical Address Space

A logical address (also called a virtual address) is generated by the CPU during program execution. A physical address is the actual address seen by the memory unit (loaded into the memory-address register).

AspectLogical Address SpacePhysical Address Space
DefinitionSet of all logical addresses generated by a program/CPU.Set of all physical addresses corresponding to the logical addresses.
Generated byCPUMemory Management Unit (MMU)
VisibilityVisible to the user/program.Not directly visible to the user.
Also calledVirtual address.Real/actual memory address.
ExistenceConceptual; need not correspond to real RAM location.Actual location in physical RAM.

Relationship: At compile time and load time the logical and physical addresses are identical. With execution-time binding, they differ, and the MMU maps logical to physical at run time. In a simple base-register scheme the mapping is:

Physical Address=Logical Address+Relocation (Base) Register\text{Physical Address} = \text{Logical Address} + \text{Relocation (Base) Register}

For example, with relocation register =14000= 14000, a logical address 346346 maps to physical address 1434614346.

memory-management
10short5 marks

Explain segmentation as a memory management scheme.

Segmentation

Segmentation is a memory-management scheme that supports the user's logical view of memory. A program is regarded as a collection of variable-sized segments — logical units such as main program, function, stack, array, global variables, each with a name and length — rather than one linear array of bytes.

Addressing

A logical address under segmentation is a two-tuple:

Logical Address=(ssegment number, doffset within segment)\text{Logical Address} = (\underbrace{s}_{\text{segment number}},\ \underbrace{d}_{\text{offset within segment}})

The mapping is done through a segment table; each entry has:

  • Base — the starting physical address of the segment.
  • Limit — the length of the segment.

Address translation:

  1. Use segment number ss to index the segment table → obtain base and limit.
  2. Check that offset d<limitd < \text{limit}; otherwise raise a trap (addressing error / segmentation fault).
  3. Physical address =base+d= \text{base} + d.

Advantages and Disadvantages

  • Advantages: Matches the programmer's logical view; allows protection and sharing at the segment level (e.g., share a code segment, set read/execute permissions per segment); no internal fragmentation.
  • Disadvantage: Because segments vary in size, segmentation suffers from external fragmentation and may require compaction.
memory-managementsegmentation
11short5 marks

What is a semaphore? Differentiate between binary and counting semaphores.

Semaphore

A semaphore is a synchronization tool — an integer variable SS that, apart from initialization, is accessed only through two atomic (indivisible) operations:

wait(S):   while (S <= 0); S = S - 1;   // P(), down
signal(S): S = S + 1;                    // V(), up

It is used to control access to shared resources and to coordinate the execution order of concurrent processes, solving the critical-section and other synchronization problems.

Binary vs Counting Semaphore

AspectBinary SemaphoreCounting Semaphore
Range of valueOnly 0 or 1.Any non-negative integer (unrestricted domain).
PurposeMutual exclusion (acts as a lock / mutex).Controls access to a resource with multiple instances.
Initial valueUsually 1.Usually NN = number of available resource instances.
Meaning1 = available, 0 = locked.Value = number of free resource instances; negative magnitude = number of waiting processes.
Use caseProtect a single critical section.Manage a pool of NN identical resources (e.g., NN printers).

In short: a binary semaphore is a special case of a counting semaphore restricted to the values 0 and 1.

synchronizationsemaphore
12short5 marks

Explain the concept of a monitor in process synchronization.

Monitor

A monitor is a high-level synchronization construct that provides a convenient and safe mechanism for process synchronization, overcoming the error-prone nature of semaphores (where a misplaced wait/signal can break mutual exclusion or cause deadlock).

Definition: A monitor is an abstract data type that encapsulates:

  • Shared variables (the monitor's internal data),
  • Procedures/methods that operate on those variables,
  • An initialization block.

Key property — automatic mutual exclusion: Only one process can be active inside the monitor at a time. The compiler/runtime enforces this, so the programmer does not place explicit locks. Other processes calling a monitor procedure are blocked until the monitor is free.

Condition variables: To allow a process to wait inside the monitor for a specific condition, monitors provide condition variables with two operations:

  • x.wait() — the calling process is suspended and releases the monitor until another process signals x.
  • x.signal()resumes exactly one process waiting on x (if none is waiting, it has no effect).
monitor ResourceAllocator {
    boolean busy;
    condition x;
    procedure acquire() {
        if (busy) x.wait();
        busy = true;
    }
    procedure release() {
        busy = false;
        x.signal();
    }
    initialization { busy = false; }
}

Thus monitors guarantee mutual exclusion automatically and use condition variables for finer-grained waiting/signalling, making concurrent programs easier to write correctly than with raw semaphores.

synchronizationmonitor

Frequently asked questions

Where can I find the BSc CSIT (TU) Operating System (BSc CSIT, CSC259) question paper 2075?
The full BSc CSIT (TU) Operating System (BSc CSIT, CSC259) 2075 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
Does the Operating System (BSc CSIT, CSC259) 2075 paper come with solutions?
Yes. Every question on this Operating System (BSc CSIT, CSC259) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
How many marks is the BSc CSIT (TU) Operating System (BSc CSIT, CSC259) 2075 paper?
The BSc CSIT (TU) Operating System (BSc CSIT, CSC259) 2075 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
Is practising this Operating System (BSc CSIT, CSC259) past paper free?
Yes — reading and attempting this Operating System (BSc CSIT, CSC259) past paper on Kekkei is completely free.