Top Banner Ad
BCS401 · 2023-2422 Questions

Operating system — 2023-24

Section A

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

What is the primary function 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 — Classification of Operating systems- Batch
Predicted

Define a batch processing system?

A batch processing system collects jobs with similar needs into a group and runs them one after another without user interaction. A resident monitor reads each job, loads it and passes control to it, then returns to read the next. Batch systems maximise processor utilisation but give no interactive response during execution.

Key Points

  • Jobs collected into a batch
  • Runs without user interaction
  • Resident monitor controls sequencing
Q1c2MUnit 2 — Principle of Concurrency
Core Concept

Define the principle of concurrency?

Concurrency is the ability of a system to make progress on several activities during the same period. On a single processor the activities are interleaved by rapid context switches so they appear simultaneous, while on a multiprocessor they can execute in parallel. Concurrency improves resource use and responsiveness but needs synchronisation to protect shared data.

Key Points

  • Several activities make progress together
  • Interleaved or truly parallel
  • Needs synchronisation
Q1d2MUnit 3 — Process States
Core Concept

Define a process state?

A process state is the current condition of a process as recorded in its process control block, such as new, ready, running, waiting or terminated. The state determines whether the process is eligible for scheduling and what transition can occur next, for example a running process that waits for input moves to the waiting state.

Key Points

  • Current condition of a process
  • Examples ready running waiting
  • Determines next transition
Q1e2MUnit 3 — Process identification information
Core Concept

Name one piece of process identification information?

One piece of process identification information is the process identifier, a unique integer assigned by the operating system when the process is created. It distinguishes the process from all others and is used in scheduling, signalling, accounting and when referring to the process in system calls and status tables.

Key Points

  • Process identifier PID
  • Unique integer from the OS
  • Used in calls and accounting
Q1f2MUnit 4 — Resident monitor
Core Concept

Define a resident monitor?

A resident monitor is the portion of an early batch operating system that stays in main memory at all times. It controls the sequence of jobs by loading each job from input, transferring control to it and reclaiming memory when it finishes, then starting the next job without operator intervention.

Key Points

  • Stays in memory always
  • Loads and starts jobs
  • Automates batch sequencing
Q1g2MUnit 5 — I/O devices
Predicted

Define an I/O subsystem?

An input output subsystem is the collection of hardware and software that manages data exchange between the computer and its peripheral devices. It includes device controllers, device drivers, interrupt handlers, buffers and the operating system routines that present a uniform interface so user programs can access devices without knowing hardware details.

Key Points

  • Manages data exchange
  • Includes controllers and drivers
  • Presents a uniform interface

Section B

7 Marks Each · 5 questions
Q2a7MUnit 1 — Time sharing
Core Concept

Compare and contrast time-sharing and multiprogramming operating system concepts?

Answer: Both techniques overlap execution to improve utilisation, but their objectives differ.

  1. Multiprogramming: several jobs reside in memory; when one waits for I/O the CPU switches to another, maximising CPU utilisation and throughput. User interaction is minimal.
  2. Time-sharing: an extension with many interactive users; each process gets a small time quantum, so response time is short.
  3. Multiprogramming uses job scheduling and I/O overlap; time-sharing additionally needs round-robin scheduling, terminal support and strong protection.

Sharing one processor among many users. Multiprogramming keeps several processes in main memory so that when one process waits for input or output, the processor switches to another and stays busy, improving utilisation but not necessarily giving fast response to any individual user. Time sharing extends multiprogramming by adding a timer interrupt and a round robin scheduler, so each process runs for a small time quantum and then yields the processor to the next. Because the switch happens many times per second, every user receives prompt interactive service and perceives a dedicated machine. Time sharing therefore emphasises response time and fairness, while plain multiprogramming emphasises throughput. A multiuser system allows several people to be logged in at the same time, each with independent processes and protected files, and it relies on time sharing to give each of them a fair share of the processor. A multiprocessing system is a different concept: it has two or more physical processors that execute processes in parallel, so it can increase throughput genuinely rather than by interleaving. Thus the multiuser versus multiprocessing distinction is about who shares the machine versus how many central processing units exist; a machine can be multiuser with a single processor, or multiprocessing with a single user running parallel threads. A good answer defines each term, contrasts time sharing and multiprogramming on response time and goal, contrasts multiuser with multiprocessing on users versus processors, and gives examples such as a Unix server for multiuser and a multicore workstation for multiprocessing. Mentioning that time sharing is built on multiprogramming plus preemption shows the relationship between the concepts.

Result: Multiprogramming keeps the CPU busy; time-sharing gives many users fast interactive response.

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

  • Multiprogramming: overlap CPU and I/O for throughput
  • Time-sharing: time slices for many interactive users
  • Both need scheduling; time-sharing needs faster response
Q2b7MUnit 2 — Mutual Exclusion
Core Concept

Explain the challenges of achieving mutual exclusion in concurrent programming?

Answer: Achieving mutual exclusion is difficult because concurrent processes interleave unpredictably and share data.

  1. Race conditions: two processes read the same value and both update it, so one update is lost; check-then-act is not atomic.
  2. Hardware visibility: writes may be reordered or held in caches, so a flag may not be seen immediately by another core.
  3. Deadlock/starvation: a flawed locking order can cause circular wait, while unfair policies let one process wait forever.
  4. Busy waiting and preemption: spinlocks waste CPU, and a process preempted while holding a lock blocks everyone.

Why exclusive access is hard. Achieving mutual exclusion in concurrent programming means ensuring that only one process or thread executes a critical section at a time. The difficulty comes from several sources. First, the simple high level statement that reads a shared variable and then writes it is not atomic; it compiles into several machine instructions, so two threads can interleave between them and lose an update. Second, achieving exclusion without special hardware requires careful protocols, and naive flag based schemes suffer from race conditions or from deadlock when both processes politely yield to each other. Third, a solution must satisfy three properties at once: mutual exclusion, meaning no two processes inside; progress, meaning that if no one is inside and some wish to enter, only those outside participate in deciding who goes next and the decision cannot be postponed indefinitely; and bounded waiting, meaning a process cannot be starved forever while others repeatedly enter. Fourth, modern multiprocessor hardware introduces memory reordering and caches, so a protocol that is correct under a sequentially consistent model can fail unless memory barriers or atomic read modify write instructions are used. Fifth, priority inversion can occur when a low priority thread holds a lock needed by a high priority thread. Sixth, holding a lock while blocking on input output can stall the whole system. Practical solutions use hardware atomic instructions to build mutex locks and semaphores, with careful attention to memory ordering and to releasing locks on every exit path. A good answer lists these challenges, explains the three correctness conditions and links the hardware memory model issue to why software only algorithms are rarely used today. Mentioning that deadlock and starvation are separate from mutual exclusion but must be handled alongside it is a useful nuance.

Result: Solutions need atomic primitives (test-and-set, compare-and-swap), memory barriers, semaphores/mutexes and a consistent lock 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

  • Interleaving causes race conditions/lost updates
  • Cache and reordering break naive software flags
  • Deadlock, starvation and busy-wait costs
Q2c7MUnit 3 — Process Control Block (PCB)
Survival ModePredicted

Explain the structure and contents of a Process Control Block (PCB)?

Answer: The PCB is a structured record in kernel memory with these contents:

  1. Process identification: PID, parent PID, user/group IDs.
  2. State and scheduling: current state, priority, queue links, CPU burst/accounting.
  3. CPU context: program counter, registers, condition codes, stack pointer.
  4. Memory and resources: page table/base-limit registers, open-file table, allocated devices, semaphore locks.

The process control block. A process is a program in execution, and the operating system must keep a data structure for every process so it can manage and resume it. That structure is the process control block, also called the task control block. It is created when a process is created and deleted when the process terminates. The PCB stores the process state, such as new, ready, running, waiting or terminated, and a process identifier that uniquely names the process. It stores the program counter, which holds the address of the next instruction, and the CPU registers, which hold the working values of the process at the moment it was last running. It also stores scheduling information such as priority, pointers to scheduling queues and the remaining time slice, memory management information such as base and limit registers or page tables, accounting information such as CPU time used and process limits, and input output status including the list of open files and allocated devices. When a process is suspended, the operating system saves its register context and state into the PCB; when the process is resumed, it restores them so execution continues exactly where it stopped. The PCB is therefore the physical embodiment of a process: a process exists as an active entity precisely because it has a PCB, while a program is a passive file on disk. A good answer defines the PCB, lists its main fields with a sentence on each, explains how it supports context switching, and distinguishes a process from a program. Mentioning that the PCB is stored in a protected kernel area that user processes cannot modify highlights why the information is trustworthy.

Result: It fully describes a process so the OS can switch, schedule and protect it; it is the kernel's representation of a process.

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

  • Identity fields (PID, parent, user)
  • State, priority and CPU register context
  • Memory map, open files and allocated devices
Q2d7MUnit 4 — Multiprogramming with fixed partitions
Core Concept

Compare and contrast multiprogramming with fixed partitions and variable partitions?

Answer:

  1. Fixed partitions: memory is statically divided into a fixed number of equal or unequal partitions at system generation. A job is loaded into a partition that fits; simple bookkeeping, no compaction, but internal fragmentation and a limit on the degree of multiprogramming.
  2. Variable partitions: partitions are created dynamically to match each job size. No internal fragmentation and more jobs can run, but external fragmentation and coalescing/compaction are needed.
  3. Fixed partitions suit simple batch systems with predictable job sizes; variable partitions suit multiprogramming with varying job sizes.

Fixed versus variable memory partitions. In multiprogramming with fixed partitions, main memory is divided at system startup into a set of partitions whose sizes are fixed, sometimes all equal and sometimes graduated. Each partition holds one process, and a job is assigned to a partition large enough for it. The scheme is simple to implement and needs little bookkeeping, and it supports multiprogramming, but it suffers internal fragmentation because a process smaller than its partition wastes the unused space inside it. It also limits the number of concurrent processes to the number of partitions, and a large job may never fit. In variable partitions, memory is allocated dynamically to exactly the size each process needs. There is no internal fragmentation because a partition matches the process, and more processes can run as long as total demand fits. The price is external fragmentation, because released blocks leave holes of irregular size that may be too small for later requests, and the operating system must maintain a free list and decide placement and coalescing. Fixed partitioning suits simple batch systems with predictable job sizes, while variable partitioning suits systems with varied and changing process sizes. Both can be improved: fixed partitions can use unequal sizes to reduce waste, and variable partitions can use compaction or paging to remove external fragmentation. A good answer defines both approaches, compares them on fragmentation, bookkeeping, degree of multiprogramming and suitability, and gives a small example showing wasted space in fixed partitions and holes in variable partitions. Mentioning that variable partitions place the burden on the allocator while fixed partitions place it on the system designer is a neat way to summarise the tradeoff.

Result: Fixed = simple but wasteful inside partitions; variable = better utilisation but requires managing holes.

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

  • Fixed: static partitions, internal fragmentation
  • Variable: dynamic sizing, external fragmentation
  • Trade-off simplicity vs memory utilisation
Q2e7MUnit 5 — RAID. File System: File concept
Survival ModePredicted

Compare and contrast different disk storage technologies, such as HDDs and SSDs?

Answer:

  1. HDD: magnetic spinning platters with moving heads; cheap per GB and high capacity, but seeks/rotation add latency (milliseconds), it is fragile and uses more power.
  2. SSD: NAND flash with no moving parts; much lower latency and higher IOPS, silent, shock-resistant and power-efficient, but cost per GB is higher and cells wear with writes (wear levelling, limited P/E cycles).
  3. Typical use: HDD for bulk archival storage, SSD for OS, databases and latency-sensitive workloads; hybrid caches combine both.

Magnetic disks versus solid state drives. Hard disk drives store data magnetically on rotating platters. A read write head on a moving arm seeks to the target track and waits for the sector to rotate beneath it, so access time is the sum of seek time and rotational latency plus transfer time. They offer very large capacity at low cost per gigabyte and good sequential throughput, but they are mechanical, vulnerable to shock, consume more power, are noisy and have millisecond latencies. Solid state drives store data in flash memory cells with no moving parts. Any block can be accessed in tens of microseconds, so random access is dramatically faster, and they are quieter, lighter, more shock resistant and more power efficient. Their disadvantages are higher cost per capacity, limited write endurance because flash cells wear out after a finite number of program erase cycles, and the need for a flash translation layer that manages wear levelling, garbage collection and bad block mapping. Both are non volatile and retain data without power, but they differ in how data is organised: HDDs use tracks, sectors and cylinders, while SSDs use pages and erase blocks. SSDs also benefit from the TRIM command to tell the drive which pages are no longer in use. A good answer compares the two technologies on storage mechanism, access time, capacity, cost, durability, power and noise, explains the role of seek and rotation for hard disks and wear levelling for solid state drives, and states typical uses: hard disks for cheap bulk archival storage and solid state drives for operating systems and performance sensitive workloads. Mentioning that the absence of mechanical latency changes file system and scheduling design is a strong closing point.

Result: SSDs win on speed and durability; HDDs win on cheap bulk capacity.

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

  • HDD: magnetic platters, moving head, ms latency
  • SSD: flash, no moving parts, microsecond latency
  • Cost/capacity vs speed/wear trade-off

Section C

7 Marks Each · 10 questions
Q3a7MUnit 1 — Multiuser Systems
Core Concept

How does a multiuser operating system differ from a multiprocessing system?

Answer: A multiuser OS lets several users log in and use the machine concurrently, while a multiprocessing (multiprocessor) OS has several CPUs executing processes in parallel.

  1. Multiuser emphasises sharing: separate accounts, memory protection, access control, accounting and isolated processes; example: a UNIX server.
  2. Multiprocessing emphasises parallel hardware: several processors execute different processes or threads, requiring symmetric multiprocessing, cache coherence and synchronisation.
  3. A system can be both: Linux supports many users on a multicore machine.

Sharing one processor among many users. Multiprogramming keeps several processes in main memory so that when one process waits for input or output, the processor switches to another and stays busy, improving utilisation but not necessarily giving fast response to any individual user. Time sharing extends multiprogramming by adding a timer interrupt and a round robin scheduler, so each process runs for a small time quantum and then yields the processor to the next. Because the switch happens many times per second, every user receives prompt interactive service and perceives a dedicated machine. Time sharing therefore emphasises response time and fairness, while plain multiprogramming emphasises throughput. A multiuser system allows several people to be logged in at the same time, each with independent processes and protected files, and it relies on time sharing to give each of them a fair share of the processor. A multiprocessing system is a different concept: it has two or more physical processors that execute processes in parallel, so it can increase throughput genuinely rather than by interleaving. Thus the multiuser versus multiprocessing distinction is about who shares the machine versus how many central processing units exist; a machine can be multiuser with a single processor, or multiprocessing with a single user running parallel threads. A good answer defines each term, contrasts time sharing and multiprogramming on response time and goal, contrasts multiuser with multiprocessing on users versus processors, and gives examples such as a Unix server for multiuser and a multicore workstation for multiprocessing. Mentioning that time sharing is built on multiprogramming plus preemption shows the relationship between the concepts.

Result: Multiuser is about many users sharing one machine; multiprocessing is about many CPUs doing work in parallel.

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

  • Multiuser = concurrent users with protection/accounting
  • Multiprocessing = multiple CPUs, parallel execution
  • They are orthogonal properties
Q3b7MUnit 1 — Operating System Structure- Layered structure
Survival Mode

Explain the structure and components of an operating system with a layered architecture?

Answer: A layered OS is built as a stack of levels, each implemented using only the operations of the layer below.

  1. Layer 0/1: hardware primitives, interrupts, process/memory support.
  2. Layer 2-3: CPU scheduling, process switching, basic memory management.
  3. Layer 4-5: device drivers, buffering, file system.
  4. Top layer: command interpreter, system-call interface and user applications.
  5. Components interact through well-defined interfaces; a request from a user program filters down and results filter up.

Building an operating system in layers. A layered operating system is structured as a stack of levels, each of which uses only the services of the layer immediately below it and provides services to the layer above. The lowest layer is the hardware interface, and higher layers add process management, memory management, file systems and finally the user interface. The first system designed this way was THE, with six layers that could be tested and debugged one at a time. The main advantage is modularity and clarity: because a layer sees only the abstract operations of the layer beneath it, a change in one layer does not ripple through the whole system, errors are easier to localise, and each layer can be verified independently. This makes the system easier to implement, debug and extend than a single monolithic program. The drawback is performance. A request from a user program must pass down through several layers, and each layer adds overhead because it performs its own parameter checking, copying and context changes. Careful design is needed to place frequently used functions in the lower layers and keep the number of layers modest; too many layers make the system noticeably slower. In practice most modern kernels are not purely layered but combine a monolithic core with layered services. A good answer defines the layered structure with a diagram of stacked layers, states the key advantage of modularity and ease of debugging, and balances it against the performance cost of passing every request through several levels. Mentioning that each layer presents an abstract machine to the layer above is the essential idea that makes the design understandable.

Result: Layered structure gives modularity, easy debugging and replacement at the cost of extra interface 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

  • Hierarchy of layers with one-way service use
  • Example layers: scheduling, memory, devices, files, UI
  • Modularity/ease of debugging vs overhead
Q4a7MUnit 3 — Deadlock: System model
Core Concept

Explore the concept of deadlock and how it can occur in concurrent systems, discussing prevention and avoidance techniques?

Answer: Deadlock is permanent blocking of a set of processes, each holding resources the others need; it requires mutual exclusion, hold-and-wait, no preemption and circular wait;

  1. Prevention: break one condition, e.g., request all resources at once (breaks hold-and-wait), deny a request if it would create a cycle, or order resource types and require increasing order (breaks circular wait).
  2. Avoidance: inspect each request with the Banker's algorithm and grant it only if the resulting state is safe; allows more concurrency than prevention but needs advance knowledge of maximum needs.
  3. Detection: build a wait for graph/resource graph and periodically check for cycles; allow the deadlock to happen, then detect it.
  4. Concurrency can also cause livelock and starvation, which are different from deadlock.

Four ways to deal with deadlock. Operating systems handle deadlock in four broad ways. Deadlock prevention breaks one of the four necessary conditions. Mutual exclusion can be relaxed by sharing resources where possible; hold and wait can be removed by requiring a process to request all resources at once; no preemption can be relaxed by allowing the system to take resources away from a waiting process; and circular wait can be prevented by imposing a total ordering on resource types and requiring requests in increasing order. Prevention is simple but often reduces resource utilisation and can cause starvation. Deadlock avoidance allows the four conditions but uses advance information to ensure the system never enters an unsafe state, the standard example being the banker's algorithm, which tests each request for safety before granting it. Avoidance needs accurate maximum claims and can be costly to run. Deadlock detection lets deadlocks occur and periodically runs an algorithm that searches the resource allocation graph or uses a banker-like check on current needs to identify a set of deadlocked processes. Once detected, the system must recover. Recovery is usually by terminating one or more deadlocked processes, choosing victims by priority and cost, or by preempting resources from some processes and rolling them back to a safe checkpoint, which requires rollback and may starve the same victim repeatedly. The tradeoffs are clear: prevention is conservative and simple, avoidance is safer but needs information, detection and recovery allow maximum concurrency but pay a cost after a deadlock happens. A good answer describes all four strategies, gives a concrete technique for each and compares their effect on concurrency, overhead and starvation. Mentioning that most general purpose operating systems simply ignore deadlock because it is rare and prevention costs more than occasional manual restart is a practical and often expected observation.

Result: Prevention is conservative, avoidance is dynamic and safe, detection accepts deadlock and recovers later.

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

  • Four necessary Coffman conditions
  • Prevention breaks a condition; avoidance uses Banker
  • Detection finds cycles after they occur
Q4b7MUnit 2 — Dekker’s solution
Survival Mode

Compare and contrast Dekker's and Peterson's algorithms for mutual exclusion, considering their advantages and limitation?

Answer: Both algorithms solve the two-process critical-section problem with flags and a turn variable, but Peterson's is simpler.

  1. Dekker: uses flag[0], flag[1] and turn; a process raises its flag, and if both are raised it yields according to turn. Correct but longer and harder to prove.
  2. Peterson: sets flag[i] = true and turn = j, then waits while flag[j] && turn == j. It satisfies mutual exclusion, progress and bounded waiting with fewer statements.
  3. Both guarantee mutual exclusion and bounded waiting; both use busy waiting and assume atomic reads/writes, so both are limited to two processes and to machines with sequential consistency.

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: Peterson's algorithm is the cleaner, easier-to-implement variant of the same turn-based idea; neither scales directly to many processes or modern relaxed memory models.

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

  • Both use flags + turn for two processes
  • Peterson: flag[i]=true; turn=j; wait while flag[j] and turn==j
  • Same properties; Peterson simpler, both busy-wait
Q5a7MUnit 3 — Recovery from deadlock
Core Concept

Evaluate strategies for deadlock prevention, avoidance, detection, and recovery in concurrent systems, highlighting their effectiveness and trade-offs?

Answer:

  1. Prevention: break mutual exclusion, hold-and-wait, no preemption or circular wait (e.g., lock ordering, all-or-nothing allocation). Easy but restrictive and lower resource utilisation.
  2. Avoidance: Banker's algorithm grants only safe requests; better utilisation but needs maximum demands and has per-request overhead.
  3. Detection: periodically search the resource graph for cycles; no restrictions on requests, but detection cost and possible repeated deadlocks.
  4. Recovery: terminate one or more deadlocked processes (all at once or one by one by cost), or preempt resources from a process and roll it back to a safe checkpoint; starvation can result if the same victim is always chosen.

Four ways to deal with deadlock. Operating systems handle deadlock in four broad ways. Deadlock prevention breaks one of the four necessary conditions. Mutual exclusion can be relaxed by sharing resources where possible; hold and wait can be removed by requiring a process to request all resources at once; no preemption can be relaxed by allowing the system to take resources away from a waiting process; and circular wait can be prevented by imposing a total ordering on resource types and requiring requests in increasing order. Prevention is simple but often reduces resource utilisation and can cause starvation. Deadlock avoidance allows the four conditions but uses advance information to ensure the system never enters an unsafe state, the standard example being the banker's algorithm, which tests each request for safety before granting it. Avoidance needs accurate maximum claims and can be costly to run. Deadlock detection lets deadlocks occur and periodically runs an algorithm that searches the resource allocation graph or uses a banker-like check on current needs to identify a set of deadlocked processes. Once detected, the system must recover. Recovery is usually by terminating one or more deadlocked processes, choosing victims by priority and cost, or by preempting resources from some processes and rolling them back to a safe checkpoint, which requires rollback and may starve the same victim repeatedly. The tradeoffs are clear: prevention is conservative and simple, avoidance is safer but needs information, detection and recovery allow maximum concurrency but pay a cost after a deadlock happens. A good answer describes all four strategies, gives a concrete technique for each and compares their effect on concurrency, overhead and starvation. Mentioning that most general purpose operating systems simply ignore deadlock because it is rare and prevention costs more than occasional manual restart is a practical and often expected observation.

Result: Prevention/avoidance are proactive; detection/recovery are reactive. Trade-off: throughput/utilisation versus overhead, complexity and rollback cost.

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

  • Four approaches: prevention, avoidance, detection, recovery
  • Recovery: process termination or resource preemption/rollback
  • Trade-off: resource utilisation vs overhead and starvation risk
Q5b7MUnit 3 — Deadlock: System model
Survival ModeRepeated

Define deadlock in operating systems, discussing the system model and conditions necessary for deadlock occurrence?

Answer: Deadlock is a state in which a set of processes is permanently blocked because each holds a resource that another process in the set needs.

  1. System model: processes request and release resource instances (R1..Rm) of types with A instances each; a request may block the process.
  2. A deadlock exists only if all four Coffman conditions hold: mutual exclusion, hold-and-wait, no preemption and circular wait;
  3. Resource-allocation graphs show cycles for single-instance resources; with multiple instances a cycle is necessary but not sufficient.
  4. Handling strategies: prevention (break a condition), avoidance (Banker's algorithm), detection and recovery.

The system model and the four necessary conditions. Deadlock is a state in which a set of processes is permanently blocked because each holds at least one resource and is waiting to acquire a resource held by another process in the set. In the system model, processes compete for a finite set of resource types such as processors, memory, files, printers and tape drives. Each resource type may have several identical instances, and a process requests, uses and then releases a resource. A deadlock can arise only when four conditions hold simultaneously, and these are known as the Coffman conditions. Mutual exclusion means at least one resource is non sharable, so only one process can use it at a time. Hold and wait means a process is holding at least one resource while waiting to acquire additional resources held by other processes. No preemption means a resource cannot be taken away from a process while it is in use; it can be released only voluntarily by the process. Circular wait means there exists a cycle of processes in which each process is waiting for a resource held by the next process in the cycle. Because all four are necessary, breaking any one of them prevents deadlock. Resource allocation graphs are used to visualise the model: processes and resource types are nodes, request and assignment edges show ownership, and a cycle in the graph indicates deadlock when each resource type has a single instance. A good answer defines deadlock, describes the system model of processes and resource instances, lists and explains all four necessary conditions, and states that all must hold together. Mentioning a concrete example such as two processes each holding one tape drive while requesting the other makes the circular wait tangible and shows why no progress is possible.

Result: Deadlock is permanent blocking caused by a circular wait under the four necessary conditions.

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
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

  • Set of processes waiting on each other's resources
  • Four Coffman conditions are necessary
  • Resource graph/Banker's for detection or avoidance
Q6a7MUnit 4 — Paging
Survival ModePredicted

Explain the principles of paging and segmentation as memory management techniques, comparing their suitability for different system architectures?

Answer:

  1. Paging: divides logical memory and physical memory into equal fixed-size pages/frames. Address = page number + offset; a page table maps pages to frames. No external fragmentation, simple allocation, but internal fragmentation in the last page and page-table overhead.
  2. Segmentation: divides the address space into variable-sized logical segments (code, data, stack, functions). Address = segment number + offset; a segment table holds base and limit. No internal fragmentation, matches programmer's view and supports protection/sharing per segment, but suffers external fragmentation and compaction.
  3. Paged segmentation: segments are divided into pages, combining logical protection with fixed-size allocation.

Two ways to divide memory. Paging and segmentation are memory management techniques that remove the need for contiguous allocation of a whole process. In paging, physical memory is divided into fixed size blocks called page frames and logical memory is divided into pages of the same size. A page table maps each logical page to a physical frame, and an address is split into a page number and an offset. Because pages are fixed size, allocation is simple, external fragmentation is eliminated, and the operating system can easily swap pages in and out; the cost is internal fragmentation in the last page and the need for page table memory. In segmentation, memory is divided into variable size logical units such as code, data, stack and heap, each with a base and a limit. Addresses are a segment number plus an offset, and the hardware checks that the offset is within the limit, which naturally supports protection and sharing of logical units. Because segments vary in size, allocation suffers external fragmentation and needs compaction, but there is no internal fragmentation within a segment. Paging is thus suited to systems that want efficient, simple allocation and easy swapping, while segmentation suits systems that emphasise logical structure, protection and sharing. Combining both, as in segmented paging, gives logical organisation plus fixed size allocation. A good answer defines both techniques, explains address translation for each, compares them on fragmentation, protection, allocation complexity and suitability, and mentions that modern systems use paging with protection bits. Mentioning that paging is invisible to the programmer while segments can correspond to programmer visible units is a useful distinction.

Result: Paging suits systems needing simple fixed-block allocation and virtual memory; segmentation suits modular program structure and fine-grained protection; hybrid schemes combine both.

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

  • Paging: fixed pages/frames, page table, internal fragmentation
  • Segmentation: variable segments, base/limit, external fragmentation
  • Hybrid paged segmentation combines protection and fixed allocation
Q6b7MUnit 4 — Virtual memory concepts
Core Concept

Discuss virtual memory concepts, including address translation, page tables, and demand paging mechanisms?

Answer: Virtual memory gives each process the illusion of a large private address space, backed by disk when needed.

  1. Address translation: CPU produces a logical address <page, offset>; the MMU/TLB and page table translate it to a physical frame address.
  2. Page table: maps each logical page to a frame plus valid, dirty, protection and reference bits.
  3. Demand paging: pages are loaded only when referenced; a page fault traps to the OS, which fetches the page from disk, updates the page table and restarts the instruction.
  4. Page replacement and thrashing control keep the working set resident; protection bits prevent illegal access.

Running programs larger than memory. Virtual memory is a technique that lets a process execute even when its entire address space is not resident in main memory. It separates logical addresses generated by the program from physical addresses in RAM through address translation hardware. The logical address space is divided into pages and physical memory into frames of the same size, with a page table recording which frame holds each resident page and whether a page is present. When a process references a page that is not resident, a page fault traps to the operating system, which locates the page on disk, finds a free frame or chooses a victim using a replacement algorithm, reads the page in, updates the page table and restarts the instruction. This mechanism is demand paging, because pages are brought in only when needed. It allows more processes to reside in a limited memory, simplifies loading and linking, and supports protection because each process has its own page table with access rights. It also relies on locality: programs reuse a small working set of pages at any time, so only a fraction of the address space is needed. If the system spends more time paging than executing, thrashing occurs and the working set is too large, which is handled by suspending processes or reducing the degree of multiprogramming. A good answer defines virtual memory, explains address translation, describes the page fault and demand paging steps, discusses protection and the role of locality, and mentions thrashing as the failure mode. Mentioning that virtual memory gives each process the illusion of a large private contiguous address space regardless of actual physical memory is the central idea that should open the answer.

Result: Virtual memory decouples logical and physical memory, allows more processes than physical memory can hold, and simplifies loading/linking/protection.

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

  • Logical to physical translation via MMU/TLB/page table
  • Page table entries hold frame and status bits
  • Demand paging loads pages on fault; replacement avoids thrashing
Q7a7MUnit 5 — File organization and access mechanism
Core Concept

Discuss the organization of files within file systems, including contiguous, linked, and indexed allocation methods?

Answer: File allocation determines how file blocks are placed on disk.

  1. Contiguous: the file occupies consecutive blocks; directory stores first block and length. Fast sequential/random access but external fragmentation and difficult growth.
  2. Linked: each block points to the next; no external fragmentation and easy growth, but random access is slow and a lost pointer destroys the rest of the file.
  3. Indexed: a dedicated index block holds pointers to all file blocks; supports direct random access and growth, but needs an extra disk read for the index and overhead for small files (hybrids use direct + single/double indirect blocks).

How files are laid out on disk. File allocation methods decide how the blocks of a file are placed on disk. Contiguous allocation stores the entire file in a set of consecutive blocks, recording only a starting block and a length. It gives excellent sequential and direct access because the address of any block is computed by addition, and it is simple to implement, but it suffers external fragmentation and requires knowing the file size in advance; growing a file may require moving it. Linked allocation stores each block with a pointer to the next block, so blocks may be scattered anywhere and there is no external fragmentation or need for advance size knowledge. It supports sequential access well but direct access is slow because following pointers requires reading each preceding block, and a lost pointer can destroy the rest of the chain. File allocation tables improve this by storing the links in a separate table at the start of the volume. Indexed allocation gives each file an index block containing pointers to all its data blocks, so both sequential and direct access are fast and there is no external fragmentation, at the cost of an extra block per file and possible overflow if the index block fills, which is handled by linked index blocks or a multi level index. The choice depends on the workload: contiguous suits sequential batch files, linked suits small files with mostly sequential access, and indexed suits databases and random access files. A good answer defines each method, describes how addresses are found, compares them on access speed, fragmentation, growth and overhead, and states which workload suits each. Mentioning that modern file systems use extents, which are runs of contiguous blocks, to combine the benefits of contiguous and indexed allocation is a strong modern addition.

Result: Contiguous is fastest but inflexible; linked is space-efficient but sequential; indexed gives flexible random access at the cost of index 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

  • Contiguous: fast, fragmentation, fixed size
  • Linked: pointers, no fragmentation, slow random access
  • Indexed: index block, random access, extra overhead
Q7b7MUnit 5 — File directories
Core Concept

Explain the structure and management of file directories, including hierarchical and flat directory structures?

Answer:

  1. Flat directory: all entries are in a single global list; lookup is by one name, fast for small systems but no grouping and duplicate names are forbidden.
  2. Hierarchical directory: a tree of directories with a root; each directory contains files/subdirectories. Paths (absolute or relative) disambiguate identical names in different folders; allows grouping, per-directory permissions and mounting of other file systems.
  3. Management uses directory entries (name -> inode), linear search/hash/B-tree indexing, and operations create/delete/rename/list with '.' and '..' links.

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: Hierarchical directories scale to many files and users; flat directories are simple but unsuitable for large systems.

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

  • Flat: one name space, collisions
  • Hierarchical: tree, paths, per-directory protection
  • Directory entries map names to inodes