Top Banner Ad
BCS401 · 2024-2521 Questions

Operating system — 2024-25

Section A

2 Marks Each · 7 questions
Q1a2MUnit 1 — Operating system and functions
Survival ModePredictedRepeated

What are the primary functions of an operating system?

An operating system manages computer hardware and provides a convenient interface for users and applications. Its primary functions are process management, memory management, file management, device management and storage management. It also provides the user interface, system protection and accounting so that several programs can share the machine safely and efficiently.

Key Points

  • Manages hardware resources
  • Process memory file and device management
  • Provides interface and protection
Q1b2MUnit 1 — Multiprocessor Systems
Core Concept

A system has 3 processors and 5 programs ready for execution. In how many ways can the processors be assigned to the programs assuming each processor executes one program at a time?

Answer: Three distinct processors are assigned three distinct programs chosen from five, and each assignment is ordered by processor identity.

  1. First processor: 5 choices of program.
  2. Second processor: 4 remaining choices.
  3. Third processor: 3 remaining choices.
  4. Total assignments = 5 x 4 x 3 = 5P3 = 60. Result: 60 different assignments (or 10 if only the unordered set of 3 selected programs were counted).

Key Points

  • Distinct processors make the assignment ordered
  • Use permutation 5P3 = 5 x 4 x 3
  • Result = 60
Q1c2MUnit 2 — Process Concept
Core Concept

What is the difference between a process and a program?

A program is a passive set of instructions stored on disk. A process is that program in execution, with a program counter, registers, an address space and a process control block that records its state. The program is static and lasts until deleted; the process is dynamic, has a lifetime and consumes resources while it runs.

Key Points

  • Program is passive on disk
  • Process is program in execution
  • Process has state and lifetime
Q1d2MUnit 2 — Producer / Consumer Problem
Core Concept

In a Producer-Consumer system, the buffer size is 4. If Producer produces 6 items and Consumer consumes 3, find the number of items in the buffer at the end.

Answer: The bounded buffer has capacity 4.

  1. The producer can deposit at most 4 items before it must wait for the consumer.
  2. Producing 6 items therefore fills the buffer to 4; the remaining 2 productions are blocked/deferred.
  3. The consumer removes 3 items, leaving 4 - 3 = 1 item in the buffer. Result: 1 item remains in the buffer at the end.

Key Points

  • Buffer capacity = 4 limits production
  • Only min(6,4) = 4 items can be in buffer before consumption
  • 4 - 3 = 1 item remains
Q1e2MUnit 2 — Process generation
Core Concept

A process executes the following code: fork(); fork(); fork(); How many processes are created in total, including the original?

Answer: Each fork() duplicates the calling process.

  1. Start with 1 original process.
  2. After fork 1: 2 processes; after fork 2: 4 processes; after fork 3: 8 processes.
  3. In general n forks produce 2^n processes including the original. Result: 2^3 = 8 processes exist in total (7 new children plus the original).

Key Points

  • Each fork doubles the number of processes
  • Sequence 1 -> 2 -> 4 -> 8
  • Total including original = 8
Q1f2MUnit 3 — Process Control Block (PCB)
Survival ModePredicted

List three components stored in a PCB.

Three components stored in a process control block are the process state, the program counter and the CPU registers. The state records whether the process is ready, running or waiting, the program counter holds the next instruction address, and the registers hold the working values saved when the process was last suspended.

Key Points

  • Process state
  • Program counter
  • CPU registers
Q1g2MUnit 4 — Page replacement algorithms
Survival ModePredicted

What is the purpose of a page replacement algorithm?

A page replacement algorithm chooses which page to remove from main memory when a page fault occurs and all frames are occupied. Its purpose is to select a victim unlikely to be needed soon, so the number of future page faults is minimised and the system spends less time moving pages between disk and memory.

Key Points

  • Chooses a victim page
  • Runs on a page fault
  • Minimises future faults

Section B

7 Marks Each · 4 questions
Q2a7MUnit 3 — Process States
Core Concept

Explain the process concept in detail with its states and state transition diagram.

Answer: A process is a program in execution with its own address space, PCB and state.

  1. States: new (being created), ready (waiting for CPU), running (instructions executing), waiting/blocked (waiting for I/O or event), terminated (finished).
  2. Transitions: new -> ready (admitted); ready -> running (dispatch); running -> ready (quantum expires or higher-priority arrival); running -> waiting (I/O request/wait); waiting -> ready (event completes); running -> terminated (exit).
  3. Diagram (textual): New -> Ready < -> Running -> Terminated, with Running -> Waiting -> Ready as the I/O loop.
  4. The kernel keeps the current state and saved context in the PCB and moves the PCB between ready and device wait queues.

The life cycle of a process. A process moves through a small set of well defined states during its lifetime. When it is first created it is in the new state while the operating system builds its process control block and allocates memory. It then enters the ready state, meaning it is loaded in main memory and waiting for the processor. When the scheduler dispatches it, it enters the running state and its instructions execute. Several transitions are possible from running. If its time quantum expires or a higher priority process becomes ready, it returns to the ready state. If it requests input output, waits for an event or waits for a signal, it moves to the waiting or blocked state, and when the event completes it returns to ready. If it finishes, it moves to the terminated state, where the operating system reclaims its resources and removes its process control block. A process may also be suspended and swapped out to disk to relieve memory pressure, giving rise to ready suspended and blocked suspended states. The state transition diagram shows these states as circles and the transitions as arrows labelled with the event that causes them: admit, dispatch, time out, wait event, event occurs and exit. The diagram is essential because it makes clear that a blocked process cannot run even if the processor is idle, and that only a process in the ready state is eligible for scheduling. A good answer defines each state, explains each transition with its triggering event, draws a labelled state diagram and explains why the distinction between ready and waiting matters for the scheduler. Mentioning that the process control block stores the current state so the operating system can track these transitions ties the diagram back to the data structure.

Result: The state-transition diagram explains how scheduling and I/O drive a process through its life cycle.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.
Process state transition diagram new ready running waiting terminated admit dispatch timeout wait event event occurs exit suspended states arise when a ready or waiting process is swapped out to disk

Key Points

  • Process = program in execution with PCB
  • Five states: new, ready, running, waiting, terminated
  • Dispatch, preemption, I/O wait/completion transitions
Q2b7MUnit 3 — Scheduling Algorithms
Predicted

Consider the set of processes with arrival time (in milliseconds), CPU burst time (in milliseconds), and priority (0 is the highest priority) shown below. None of the processes have I/O burst time.

Process Arrival Time BurstTime Priority
P1 0 11 2
P2 5 28 0
P3 12 2 3
P4 2 10 1
P5 9 16 4

Draw the Gantt chart and find average waiting time using preemptive priority scheduling algorithm.

Answer: Preemptive priority scheduling (lower number = higher priority) always executes the highest-priority ready process.

Process Arrival Burst Priority
P1 0 11 2
P2 5 28 0
P3 12 2 3
P4 2 10 1
P5 9 16 4

Gantt chart: | P1 0-2 | P4 2-5 | P2 5-33 | P4 33-40 | P1 40-49 | P3 49-51 | P5 51-67 |

Process Completion Turnaround Waiting
P1 49 49 38
P2 33 28 0
P3 51 39 37
P4 40 38 28
P5 67 58 42

Working through preemptive priority scheduling. In preemptive priority scheduling each process has a priority, with a smaller number taken as higher priority here, and the processor always runs the ready process with the best priority. If a newly arrived process has a better priority than the currently running one, the current process is preempted and returned to the ready queue with its remaining burst preserved. For the given processes, P1 arrives at time zero with burst eleven and priority two, so it starts alone. At time two P4 arrives with burst ten and priority one, which is better than P1's two, so P4 preempts P1 after P1 has used two units and has nine left. At time five P2 arrives with burst twenty eight and priority zero, the highest of all, so it preempts P4, which has used three units and has seven left. P2 runs continuously from time five to time thirty three because neither P5 arriving at nine with priority four nor P3 arriving at twelve with priority three can beat priority zero. When P2 finishes at thirty three, the ready queue holds P4 with seven left, P1 with nine left, P3 with two and P5 with sixteen. P4 runs from thirty three to forty, P1 from forty to forty nine, P3 from forty nine to fifty one, and P5 from fifty one to sixty seven. The Gantt chart segments are therefore P1 zero to two, P4 two to five, P2 five to thirty three, P4 thirty three to forty, P1 forty to forty nine, P3 forty nine to fifty one, P5 fifty one to sixty seven. Waiting times are completion minus arrival minus burst, giving thirty eight, zero, thirty seven, twenty eight and forty two for P1 through P5, and the average waiting time is one hundred and forty five divided by five, which is twenty nine milliseconds. A good answer draws the Gantt chart to scale, shows each preemption point, tabulates completion and waiting times and states the average clearly.

Result: Average waiting time = (38+0+37+28+42)/5 = 29 ms.

O(nlog⁡n)O(n \log n)
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.
Preemptive priority Gantt chart P1 P4 P2 P4 P1 P3 02533404967 P1 0-2, P4 2-5, P2 5-33, P4 33-40, P1 40-49, P3 49-51, P5 51-67 waiting: P1 38, P2 0, P3 37, P4 28, P5 42 average waiting time = 145/5 = 29 ms

Key Points

  • Lower priority number runs first, preempting lower priority
  • Gantt: P1 0-2, P4 2-5, P2 5-33, P4 33-40, P1 40-49, P3 49-51, P5 51-67
  • Average waiting time = 29 ms
Q2c7MUnit 3 — Scheduling Algorithms
Core Concept

Compare and contrast FCFS, SJF, and Round Robin scheduling algorithms.

Answer:

  1. FCFS: non-preemptive, serves processes in arrival order. Simple and fair but can cause the convoy effect and long average waiting time.
  2. SJF: selects the shortest (next) burst; non-preemptive or preemptive (SRTF). Gives minimum average waiting time but can starve long jobs and needs burst estimates.
  3. Round Robin: FCFS with a time quantum q; each process runs at most q then goes to the tail of the ready queue. Good response/time-sharing; average waiting depends on q (q too small increases context switches, q too large degenerates to FCFS).

Three classic scheduling algorithms. First come first served, or FCFS, runs processes in arrival order and is simple and fair in a queue sense, but it is non preemptive and a long process at the front makes all later processes wait, producing the convoy effect. Its average waiting time can be large and it is poor for interactive systems. Shortest job first, or SJF, selects the process with the smallest next CPU burst. It is provably optimal among non preemptive algorithms for minimising average waiting time, but it needs knowledge or an estimate of burst length, which is usually predicted from past behaviour using exponential averaging. Its weakness is starvation of long processes when short ones keep arriving; the preemptive version, called shortest remaining time first, can also cause starvation and requires careful timing. Round Robin is designed for time sharing. Each process gets a small time quantum, typically ten to a hundred milliseconds, and is placed at the tail of a circular ready queue when its quantum expires. It is fair and gives excellent response time, and its average waiting time depends heavily on the quantum: a very small quantum causes many context switches and high overhead, while a very large quantum degenerates toward FCFS. If the quantum is chosen so that most processes finish within one slice, response is good. A good answer defines each algorithm, states whether it is preemptive, gives an advantage and a disadvantage for each, and explains the convoy effect, starvation and the quantum tradeoff. Mentioning that FCFS and SJF optimise different objectives while Round Robin optimises responsiveness ties the comparison together.

Result: FCFS optimises simplicity, SJF optimises average waiting time, RR optimises responsiveness/fairness; RR with q = infinity becomes FCFS.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • FCFS: arrival order, convoy effect
  • SJF: shortest burst, minimum average waiting, starvation
  • RR: time quantum, fair interactive response
Q2d7MUnit 4 — Page replacement algorithms
Core Concept

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, find the number of page faults that will occur during execution of the process.

Answer: With 3 frames and a 4-reference lookahead, on a fault we evict the resident page whose next use lies farthest ahead in the current 4-page window (a page absent from the window is evicted first). References: 1,3,2,4,2,3,1,2,4,3,1,4. 1: fault [1]; 2: fault [1,3]; 3: fault [1,3,2]; 4: window [4,2,3,1], evict 1 -> [3,2,4]; 5(2): hit; 6(3): hit; 7(1): window [1,2,4,3], evict 3 -> [2,4,1]; 8(2): hit; 9(4): hit; 10(3): window [3,1,4], page 2 absent -> evict 2 -> [4,1,3]; 11(1): hit; 12(4): hit.

Deciding which page to evict. When a page fault occurs and all frames are occupied, the operating system must choose a victim page to remove. Page replacement algorithms differ in which page they select and in how many faults they produce for a given reference string. The optimal algorithm, also called MIN, replaces the page whose next use is furthest in the future; it produces the fewest possible faults but cannot be implemented in general because future references are unknown, so it serves as a benchmark. First in first out replaces the oldest page, which is simple but ignores usage and suffers Belady's anomaly, where more frames can paradoxically cause more faults. Least recently used replaces the page that has not been used for the longest time, approximating the optimal choice using recent history; it performs well but needs hardware support such as a reference bit, a stack or counters to be efficient. Clock or second chance uses a circular list and a reference bit, giving a cheap approximation to least recently used. Counting based algorithms such as least frequently used keep a counter of accesses. For a reference string processed with three or four frames, the fault count is obtained by stepping through the string, marking hits, and on each miss selecting the victim according to the rule, counting every miss as a fault. A good answer explains the goal of minimising faults, describes optimal, first in first out and least recently used, traces the given reference string with a frame table, states the fault count and notes Belady's anomaly and the fact that optimal is unrealisable. Mentioning that bringing in a page may require writing a dirty victim back to disk adds realism to the cost discussion.

Result: Number of page faults = 6 (at references 1, 2, 3, 4, 7 and 10).

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Lookahead window size = 4 including current reference
  • Evict page absent/farthest in window
  • Faults at positions 1,2,3,4,7,10 = 6

Section C

7 Marks Each · 10 questions
Q3a7MUnit 1 — Classification of Operating systems- Batch
Survival ModePredicted

Discuss the differences between Operating Systems with Batch, Interactive, and Time Sharing real-world applications.

Answer: Batch, interactive and time-sharing systems differ mainly in user interaction and goal.

  1. Batch: jobs are submitted together, no user during execution; maximises throughput; example: nightly payroll or billing runs.
  2. Interactive: a single user issues commands and sees immediate results; example: a PC running an editor.
  3. Time-sharing: many interactive users share the CPU by rapid time slicing, giving each the illusion of a dedicated machine; example: a UNIX server with many terminals.
  4. Batch tolerates long turnaround; time-sharing minimises response time and requires scheduling, memory protection and accounting.

Families of operating systems. Operating systems are classified by how they handle work and how users interact with them. A batch system collects jobs into a queue and runs them one after another without user interaction, using a resident monitor to load and run each job automatically. It maximises processor utilisation but gives no interactive feedback, and it was the earliest practical design. An interactive system allows a user to communicate directly with the running program through a terminal or graphical interface, receiving immediate responses, which suits editing, browsing and design work. A time sharing system is a multi tasking interactive system that divides processor time into short slices and switches rapidly among many users or processes, so each user perceives a dedicated machine. It adds fairness and responsiveness to multiprogramming. A multiuser system lets several users share one computer concurrently, protecting each user's files and processes, as in a Unix server. A multiprocessing or parallel system has more than one processor and can execute several processes truly simultaneously for higher throughput. Real examples make the classification concrete: early IBM mainframes with punched card job streams were batch systems; modern Linux and Windows desktops are interactive, multiuser, multitasking systems; a supercomputer running climate models is a multiprocessing system, and a web server handling thousands of sessions is a time sharing multiuser system. A good answer names each class, explains its defining behaviour, contrasts batch with interactive and time sharing, and attaches at least one real example to each class. Noting that modern general purpose systems combine several of these properties in one design is a useful closing observation.

Result: Batch optimises throughput, interactive optimises one user's response, time-sharing optimises fair fast response for many users.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Batch: no interaction, high throughput
  • Interactive: immediate single-user response
  • Time-sharing: many users, time slices, fair response
Q3b7MUnit 2 — Semaphores
Survival ModePredicted

Two semaphores S1 and S2 are both initialized to 1. Process P1 executes wait(S1); wait(S2); and Process P2 executes wait(S2); wait(S1);. Explain how a deadlock may occur and under what sequence.

Answer: The two processes can deadlock through a circular wait on the two semaphores.

  1. Both S1 and S2 start at 1.
  2. Sequence: P1 executes wait(S1) -> S1 = 0; P2 executes wait(S2) -> S2 = 0.
  3. P1 then executes wait(S2), which blocks because S2 = 0; P2 executes wait(S1), which blocks because S1 = 0.
  4. Each process holds one semaphore and waits for the one held by the other: circular wait, no preemption, mutual exclusion and hold-and-wait all hold.

When two semaphores create a cycle. A semaphore is an integer variable used for synchronisation, accessed only through the atomic operations wait and signal. Wait decrements the value and blocks the process if the result is negative; signal increments it and wakes a waiting process. With two semaphores S1 and S2 both initialised to one, each semaphore initially permits one process to pass. Deadlock arises from the order in which the two processes acquire them. Suppose process P1 executes wait on S1 and succeeds, reducing S1 to zero. At the same moment process P2 executes wait on S2 and succeeds, reducing S2 to zero. P1 then executes wait on S2, which is now zero, so P1 blocks holding S1. P2 then executes wait on S1, which is also zero, so P2 blocks holding S2. Each process holds the resource the other needs and waits for it while holding its own, forming a circular wait, and neither can proceed to release anything. This is the classic deadly embrace and it shows that semaphores prevent races but do not by themselves prevent deadlock. The deadlock occurs only for this interleaving; if P1 acquired both semaphores before P2 started, both would complete. Remedies include imposing a global acquisition order so that every process takes S1 before S2, acquiring all needed semaphores atomically, or using a timeout and backoff. A good answer explains the wait and signal semantics, traces the exact interleaving step by step with semaphore values, identifies the circular wait condition and proposes at least one prevention method. Mentioning that mutual exclusion is satisfied but progress is lost makes the point that correctness requires more than safety.

Result: The deadlock occurs with the interleaving P1:wait(S1), P2:wait(S2), P1:wait(S2), P2:wait(S1); it can be avoided by always acquiring locks in the same order.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Both semaphores start at 1
  • Interleaving of the four waits causes circular wait
  • Consistent lock ordering prevents it
Q4a7MUnit 2 — Critical Section Problem
Core Concept

Define the Critical Section Problem and list the conditions that a solution must satisfy.

Answer: The critical-section problem is to design a protocol so that no two processes execute their critical sections at the same time. Each process code has entry section, critical section, exit section and remainder section. A valid solution must satisfy:

  1. Mutual exclusion: if Pi is in its critical section, no other process is in its critical section.
  2. Progress: if no process is in the critical section and some wish to enter, only those not in their remainder section participate and selection cannot be postponed indefinitely.
  3. Bounded waiting: after a process requests entry, there is a bound on how many times other processes may enter before it.

The requirements for a correct solution. The critical section problem is to design a protocol that coordinates several processes so that each executes its critical section, where it accesses shared data, without conflicting with the others. The problem is stated for n processes, each with a section that changes common state. A correct solution must satisfy three conditions. Mutual exclusion means that if one process is executing in its critical section, no other process may be executing in its critical section. Progress means that if no process is in the critical section and some processes wish to enter, only those processes that are interested may participate in deciding which one enters next, and this selection cannot be postponed indefinitely; the decision must not be made by a process outside the critical section that has no interest. Bounded waiting means that there must be a limit on the number of times other processes are allowed to enter their critical sections after a process has requested entry and before that request is granted, so no process is starved. In addition, a solution should be independent of the relative speeds of the processes and should work when a process is interrupted or stopped in its critical section, although crash tolerance is usually treated separately. Solutions may use software protocols such as Peterson's algorithm for two processes, hardware atomic instructions such as test and set or compare and swap, or operating system mechanisms such as mutex locks and semaphores. A good answer defines the critical section, states and explains all three requirements with careful wording, notes the assumption about process speeds and names the main classes of solution. Mentioning that mutual exclusion alone is not enough because a solution that blocks everyone also satisfies it but violates progress is a common examiner point.

Result: These three requirements, plus no assumption about relative speeds, define a correct critical-section solution.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Entry/critical/exit/remainder sections
  • Mutual exclusion
  • Progress and bounded waiting
Q4b7MUnit 3 — Avoidance and detection
Core Concept

A system shares 9 tape drives. The current allocation and maximum requirement of tape drives for three processes are shown below:

Process Current Allocation Maximum Requirement
P1 3 7
P2 1 6
P3 3 5

Which of the following best describes the current state of the system? Explain.

  1. Safe, Deadlocked
  2. Safe, Not Deadlocked
  3. Not Safe, Deadlocked
  4. Not Safe, Not deadlocked

Answer: Total tape drives = 9; allocated = 3 + 1 + 3 = 7; Available = 2.

  1. Remaining needs: P1 = 7-3 = 4, P2 = 6-1 = 5, P3 = 5-3 = 2.
  2. Available (2) satisfies P3's need: P3 finishes and releases 3 drives -> Available = 5.
  3. P1's need 4 is now satisfied: P1 finishes and releases 3 -> Available = 8.
  4. P2's need 5 is satisfied: P2 finishes.

Applying the banker's algorithm. The banker's algorithm is a deadlock avoidance scheme that tests whether a requested allocation leaves the system in a safe state. A state is safe if there exists a sequence of all processes such that each can obtain its remaining needs from the resources currently available plus those released by earlier processes in the sequence. The algorithm maintains the allocation matrix of resources currently held, the maximum matrix of resources each process may ever need, and the need matrix obtained by subtracting allocation from maximum. It also keeps an available vector of free resources. Safety is tested by initialising a work vector to available and repeatedly finding a process whose need is no greater than work; when found, its allocation is added to work and it is marked finished. If every process can be finished, the state is safe. For a request, the algorithm first checks that the request does not exceed the process's need and does not exceed available, then tentatively grants it and runs the safety test; the request is granted only if the resulting state is safe. In the tape drive example, P1 holds three of seven maximum, P2 holds one of six, and P3 holds three of five, so their needs are four, five and two. With three drives free, only P3 can finish first, releasing three to make six free, then P1 or P2 can finish, so a safe sequence exists and the system is safe and not deadlocked. In the larger snapshot problem, the need matrix is computed by subtraction, a safe sequence is found from the available vector, and the request from T1 is checked for need and availability and then tested for safety before being granted. A good answer states the data structures, performs the subtraction, walks through the safety sequence and states the conclusion with reasoning. Mentioning the distinction between a safe state and deadlock, where deadlock implies unsafe but unsafe does not necessarily imply deadlock yet, is important.

Result: Safe sequence <P3, P1, P2>. The system is Safe, Not Deadlocked - option 2.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Available = 9 - 7 = 2 drives
  • Needs: P1=4, P2=5, P3=2
  • Safe sequence P3,P1,P2 -> option 2
Q5a7MUnit 2 — Dekker’s solution
Predicted

Discuss the limitations of Dekker's and Peterson's solutions when applied to modern multiprocessor architectures.

Answer: Dekker's and Peterson's algorithms are correct software solutions for two processes on an ideal sequential machine, but they rely on assumptions that modern hardware and larger systems violate.

  1. They are restricted to two processes; many critical sections need n-process solutions or hardware primitives.
  2. They depend on atomic reads/writes and on memory ordering. Modern compilers and CPUs reorder loads/stores, and cache coherence means a flag update is not instantly visible to other cores, so extra memory barriers or atomic instructions are required.
  3. They are busy-waiting algorithms: a waiting process consumes CPU cycles, unacceptable with many threads or battery devices.
  4. Fairness depends on carefully timed flag turns; on multiprogramming a preempted process can delay entry unpredictably.

Software solutions to mutual exclusion. Dekker's algorithm and Peterson's algorithm are classic software based solutions to the two process critical section problem. Both use shared boolean flags and a turn variable, and both rely on the assumption that reads and writes of a single word are atomic. Dekker's algorithm uses two interested flags plus a turn variable to break symmetry. A process raises its flag, and if the other is also interested it checks the turn variable and yields until it is its turn, using a careful sequence of raising and lowering its flag to avoid both waiting forever. It guarantees mutual exclusion, progress and bounded waiting, and it is historically important as the first correct solution that needs no special hardware instructions. Peterson's algorithm is a simpler combination of the same ideas: each process sets its own flag and then sets turn to the other process before entering the critical section. Because the flag and turn are written in that order, if both processes try to enter, the one that wrote turn last yields, so only one enters, and waiting is bounded to one entry by the other. Peterson is easier to understand and prove than Dekker. Both algorithms have limitations. They work for exactly two processes, do not extend directly to many processes without extra structure, and assume sequential consistency. On modern multiprocessor systems with store buffering, out of order execution and weak memory models, the naive versions can fail unless memory barriers or atomic instructions are used, which is why real systems rely on hardware primitives such as compare and swap or load linked store conditional. A good answer explains both algorithms, compares their complexity and properties, and states the memory model limitation clearly. Mentioning that hardware atomic instructions replace these software protocols in practice completes the answer.

Result: Modern systems implement mutual exclusion with hardware atomic operations (test-and-set, compare-and-swap) plus memory barriers, semaphores and mutexes built on them.

O(nlog⁡n)O(n \log n)
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Limited to two processes
  • Depend on atomic, ordered memory accesses
  • Busy waiting and no scalability on multicore
Q5b7MUnit 5 — File directories
Core Concept

Explain file directories and directory structures in operating systems.

Answer: A file directory is a kernel-maintained structure mapping file names to file control blocks/inodes and their locations on disk.

  1. A directory entry stores the name, type, size, location, timestamps and access rights.
  2. Single-level: one flat list, simple but name collisions.
  3. Two-level: separate directory per user, avoids collisions between users.
  4. Tree/hierarchical: directories contain files and subdirectories; paths may be absolute or relative, with '.' and '..'; supports grouping and sharing via links.
  5. Operations: create, delete, list, search, rename and traverse; implementation uses linear lists, hash tables or B-trees.

Organising files into directories. A file system uses directories to organise files. A directory is itself a file that contains a table mapping file names to the locations of their data on disk. A flat or single level directory keeps all files in one list, which is simple but cannot have duplicate names and becomes unwieldy as the number of files grows. A two level directory gives each user a separate directory, solving name collisions among users but not within a user's directory. A hierarchical or tree structured directory allows directories to contain subdirectories and files, giving a natural nesting structure, unique path names, efficient organisation and easy protection and grouping. Paths may be absolute from the root or relative to the current working directory, and operations include create, delete, list, rename and traverse. Implementation depends on the directory entry structure: entries may store file names with pointers to file control blocks, or use a table with attributes such as type, size, protection and timestamps. A balanced tree such as a B tree keeps lookups fast even with many entries. More general structures use acyclic graphs or graphs with links, allowing a file to appear in more than one directory, but then deletion and cycle detection need care. A good answer defines a directory, contrasts flat and hierarchical structures, explains path names and typical operations, and discusses how directory entries are stored and searched. Mentioning that the directory provides the mapping from a human readable name to a physical location is the key function that should anchor the answer.

Result: Directories organise files and translate a human-readable path into the file's physical metadata.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Directory maps names to inodes/FCBs
  • Single, two-level and tree structures
  • Path resolution, search and sharing via links
Q6a7MUnit 4 — Multiprogramming with variable partitions
Survival Mode

Discuss multiprogramming with variable partitions and how it improves memory utilization.

Answer: In multiprogramming with variable (dynamic) partitions, main memory is divided on demand into partitions whose size exactly matches each job.

  1. The OS keeps a table of free/allocated blocks and uses first-fit, best-fit or worst-fit to allocate a hole.
  2. When a job terminates, its partition is freed and adjacent holes are coalesced.
  3. Compared with fixed partitions, there is no internal fragmentation because a partition matches the job size.
  4. However, holes of awkward sizes accumulate (external fragmentation), which may require compaction to shift jobs and create a large contiguous hole.

Allocating memory in variable sized blocks. Multiprogramming with variable partitions allocates main memory dynamically to the exact size of each process rather than dividing it into fixed equal blocks. When a process is admitted, the operating system finds a free hole large enough and carves out a partition of the required size, leaving the remainder as a new hole. When a process terminates, its partition is returned to the pool of free memory and may be merged with adjacent holes to form a larger one. The operating system tracks memory with a list or bitmap of allocated and free blocks, and chooses a hole using a placement strategy such as first fit, best fit or worst fit. First fit takes the first adequate hole and is fast; best fit takes the smallest adequate hole and reduces leftover but can create many tiny holes; worst fit takes the largest hole and leaves a more usable remainder. Variable partitioning improves memory utilisation compared with fixed partitions because a small process does not waste a large fixed block, and it supports processes of different sizes without internal fragmentation. Its disadvantage is external fragmentation: after many allocations and releases, free memory is split into many small non contiguous holes whose total may be large but none big enough for a new process. Compaction, which shifts processes to gather free space, or paging, which allows non contiguous allocation, are the standard remedies. A good answer explains how partitions are created and freed, describes the placement strategies, states the improvement in utilisation and explains external fragmentation with its remedy. Mentioning that the choice of placement strategy affects both speed and fragmentation ties the details together.

Result: Variable partitions improve memory utilisation by removing internal fragmentation, at the cost of external fragmentation and compaction overhead.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Partitions created to exact job size at load time
  • First/best/worst-fit allocation and coalescing
  • No internal fragmentation but external fragmentation/compaction
Q6b7MUnit 5 — Disk storage and disk scheduling
Survival ModePredictedRepeated

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. Calculate the total head movement (in cylinders) required to service these requests.

Answer: Queue = 47, 38, 121, 191, 87, 11, 92, 10; head starts at 63 moving upward; cylinders 0-199. C-SCAN: service upward 87, 92, 121, 191, go to 199, wrap to 0, then service 10, 11, 38, 47. Movement = (87-63)=24 + (92-87)=5 + (121-92)=29 + (191-121)=70 + (199-191)=8 + (199-0)=199 + 10 + 1 + 27 + 9 = 382 cylinders. C-LOOK: service upward 87, 92, 121, 191, then jump directly to the lowest pending request 10 (no travel to 199/0), then 11, 38, 47. Movement = 24 + 5 + 29 + 70 + (191-10)=181 + 1 + 27 + 9 = 346 cylinders.

Reducing disk head movement. A magnetic disk stores data on concentric tracks divided into sectors, and a read or write requires moving the head to the correct track and waiting for the sector to rotate under it. Because seek time dominates, disk scheduling algorithms choose the order in which pending requests are serviced to minimise total head movement. First come first served handles requests in arrival order, which is fair but can move the head erratically. Shortest seek time first services the nearest request next, reducing movement but risking starvation of requests at the far end when new near requests keep arriving. SCAN, or the elevator algorithm, moves the head in one direction servicing all requests on the way, reverses at the end of the disk, so it bounds starvation. C-SCAN moves only in one direction, returning to the beginning without servicing requests on the return trip, which gives more uniform response times. C-LOOK is like C-SCAN but reverses at the furthest pending request instead of travelling to the physical end of the disk, saving the empty travel to the last cylinder. For a queue on cylinders between zero and one hundred and ninety nine with the head at sixty three moving upward, C-SCAN continues upward serving all requests then wraps to zero, while C-LOOK stops at the highest pending request and jumps back to the lowest pending request. Counting the absolute differences between successive positions gives the total head movement; the C-LOOK total is smaller because it avoids travel beyond the last request. A good answer defines seek time and rotational latency, describes each algorithm with the direction of motion, traces the given queue for both C-SCAN and C-LOOK with the head positions and states the totals. Mentioning that modern solid state disks have no moving head, so these algorithms are less relevant there, is a useful modern note.

Result: C-SCAN = 382 cylinders; C-LOOK = 346 cylinders.

O(nlog⁡n)O(n \log n)
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • C-SCAN goes to 199 then wraps to 0
  • C-LOOK jumps directly to lowest request
  • Total head movement: 382 and 346 cylinders
Q7a7MUnit 4 — Paging
Predicted

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?

Answer: Page size = 2048 bytes = 2^11 bytes, so the page offset needs 11 bits.

  1. Logical address = 32 bits, therefore page number bits = 32 - 11 = 21 bits.
  2. Number of pages in the logical address space = 2^21.
  3. The page table needs one entry per logical page (maximum), i.e., 2^21 entries.
  4. The 20-bit physical address gives 2^(20-11) = 2^9 = 512 frames, but page-table length is set by the logical space.

Counting page table entries. In a demand paging system the logical address is divided into a page number and an offset, and the page size determines how many offset bits are needed. The logical address space is two raised to the number of logical address bits, and dividing that by the page size gives the number of pages, which is exactly the number of entries required in the page table, assuming one entry per logical page. Here the logical address is thirty two bits, so the logical address space is two to the thirty two bytes. The page size is two thousand and forty eight bytes, which is two to the eleven, so eleven bits are used as the page offset. The remaining bits form the page number, that is thirty two minus eleven equals twenty one bits. The number of pages is therefore two to the twenty one, which is two million ninety seven thousand one hundred and fifty two entries. The twenty bit physical address implies eighteen physical page number bits after the same eleven offset bits, so main memory can hold two to the eighteen frames, but that does not change the number of logical page table entries. Each entry typically stores a frame number plus valid, protection, dirty and reference bits, so with four bytes per entry the table would occupy about eight megabytes, which motivates multilevel page tables, hashed page tables or inverted page tables to reduce memory use. A good answer shows the address split, computes the offset and page number bit counts, derives the entry count as a power of two and gives the decimal value, then comments on the storage cost. Mentioning that the physical address width limits the number of frames but not the number of logical pages prevents a common confusion.

Result: Maximum entries in the page table = 2^21 = 2,097,152.

O(nlog⁡n)O(n \log n)
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • Page size 2^11 -> 11 offset bits
  • 32 - 11 = 21 page-number bits
  • Page table entries = 2^21 = 2,097,152
Q7b7MUnit 5 — RAID. File System: File concept
Predicted

Discuss RAID 0, RAID 1, and RAID 5 in detail.

Answer:

  1. RAID 0: block-level striping across all disks, no redundancy. Maximum throughput and full capacity, but any disk failure loses all data; suitable for scratch/temp data.
  2. RAID 1: exact mirror of data on two or more disks. 100% redundancy, fast reads and simple recovery, but usable capacity is only one disk's size; used for critical system disks.
  3. RAID 5: block striping with distributed parity; parity is rotated across members, so a single disk failure can be reconstructed. Capacity = (N-1) x disk size; good read throughput but write penalty for parity update and long rebuild; common for file servers.

Combining disks for speed and reliability. RAID, which stands for redundant array of independent disks, combines several physical disks into one logical unit to improve performance, reliability, or both. RAID 0 uses striping, spreading data across all disks in blocks. It gives excellent throughput because multiple disks work in parallel and uses the full capacity, but it provides no redundancy, so the failure of any disk loses all data. RAID 1 uses mirroring, writing identical data to two or more disks. It gives high read performance and survives the failure of a mirror member, but its usable capacity is only that of one disk, so the cost is high. RAID 5 uses block level striping with distributed parity. Parity for each stripe is stored on a different disk, so the array tolerates the loss of one disk and uses all but one disk's worth of capacity. Reads are fast because data is spread across disks, while writes are slower because parity must be read, computed and written. RAID 6 adds a second parity block and survives two disk failures, and RAID 10 combines mirroring and striping for both speed and safety. The general advantages of RAID are increased throughput through parallelism, fault tolerance through redundancy, and the ability to rebuild a failed disk from remaining data and parity. A good answer defines RAID, explains striping, mirroring and parity, describes RAID levels zero, one and five with capacity and fault tolerance for each, and lists the overall advantages with the tradeoff between performance, capacity and reliability. Mentioning that rebuild time and the risk of a second failure during rebuild are practical concerns shows depth.

Result: RAID 0 = speed/no fault tolerance; RAID 1 = mirror/expensive but safest; RAID 5 = balanced capacity, performance and single-disk recovery.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: Explain the mechanism or algorithm step by step, support it with a diagram, table or worked calculation, and state the final result with clear units.

Key Points

  • RAID 0: striping, no redundancy
  • RAID 1: mirroring, 50% utilisation
  • RAID 5: distributed parity, one-disk recovery