BIT204 · TU past paper
Operating Systems 2078 question paper
The complete TU 2078 exam paper for Operating Systems (BIT204), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- 110 marksNumericalDisk scheduling algorithmsHideAnswer
Suppose that a disk has 100 cylinders, numbered 0 to 99. The drive is currently serving a request at cylinder 45. The queue of pending request, in FIFO order is: 88, 72, 13, 74, 48, 9, 22, 50, 35 and 30. What is the total distance (in cylinders) that the disk arm moves to satisfy all pending request for each of the following disk scheduling algorithms? a) FCFS b) SCAN c) SSTF[10]
- Total cylinders: 0 to 99 (100 cylinders) - Current head position: 45 - FIFO request queue: 88, 72, 13, 74, 48, 9, 22, 50, 35, 30 --- Serve in FIFO order: $45 \to 88 \to 72 \to 13 \to 74 \to 48 \to 9 \to 22 \to 50 \to 35 \to 30$ Move Di...
- 210 marksProducer consumer problem with semaphoreHideAnswer
What is critical section? What are the operations that can be performed on the semaphore? Explain the solution to producer consumer problem using semaphore.[10]
--- A critical section is a segment of code in a process where the process accesses and manipulates shared resources (such as shared variables, files, or data structures) that must not be accessed by more than one process at the same tim...
- 310 marksVirtual memory technique and purposeHideAnswer
Why virtual memory technique is used in the computer system? What is logical address? Explain the process of conversion of logical address to physical address in single level paging scheme.[10]
Note: Reference notes were not available for this topic. The answer below is based on standard Operating Systems curriculum as taught in TU BSc CSIT (consistent with Silberschatz/Galvin and similar texts used in the program). --- Virtual...
- 45 marksKernel definition and roleHideAnswer
What is kernel? Differentiate between monolithic and microkernel structure. [5]
The kernel is the core component of an operating system that acts as a bridge between application software and computer hardware. It manages system resources such as CPU, memory, and I/O devices, and provides essential services to all ot...
- 55 marksDMA definition and purposeHideAnswer
What is DMA? Explain how it works in brief with suitable diagram. [5]
Direct Memory Access (DMA)
Definition
DMA (Direct Memory Access) is a feature of computer systems that allows certain hardware subsystems (such as disk controllers, network cards, or sound cards) to access main memory (RAM) independently of the CPU. It enables data transfer between I/O devices and memory without continuous CPU involvement, freeing the CPU to perform other tasks during the transfer.
Why DMA is Needed
Without DMA, the CPU must supervise every byte transferred between an I/O device and memory (programmed I/O), which wastes CPU cycles. DMA offloads this work to a dedicated DMA Controller (DMAC).
Key Components
Component Role DMA Controller (DMAC) Manages the data transfer independently Source Address Register Holds the source memory/device address Destination Address Register Holds the destination memory address Count Register Holds the number of bytes/words to transfer Control Register Specifies direction and mode of transfer
How DMA Works (Step-by-Step)
Step 1: CPU Initialization
- The CPU programs the DMA controller by providing:
- Source address
- Destination address
- Number of bytes to transfer
- Direction of transfer (read/write)
- The CPU then continues its own tasks.
Step 2: DMA Request
- The I/O device signals the DMAC that it is ready to transfer data (via DMA Request line - DREQ).
Step 3: Bus Request
- The DMAC requests control of the system bus from the CPU by asserting the Bus Request (BR) signal.
Step 4: Bus Grant
- The CPU completes its current bus cycle and grants the bus to the DMAC by asserting Bus Grant (BG). The CPU is now temporarily disconnected from the bus (CPU is in a "hold" state).
Step 5: Data Transfer
- The DMAC takes control of the address bus, data bus, and control bus.
- Data is transferred directly between the I/O device and memory, one block at a time, without CPU involvement.
- The address and count registers are updated after each transfer.
Step 6: Transfer Complete
- When the count reaches zero (all data transferred), the DMAC sends an interrupt to the CPU to notify it that the transfer is complete.
- The CPU resumes control of the bus.
Diagram
+------------------+ | CPU | +--------+---------+ | BR / BG (Bus Request / Bus Grant) | +--------+---------+ | DMA Controller |<-------- DREQ (from I/O Device) | (Source Addr Reg)| | (Dest Addr Reg) | | (Count Reg) | +---+----------+---+ | | Address/Data/Control Bus | | +-------+--+ +--+--------+ | Main | | I/O Device| | Memory | | (Disk,NIC)| +----------+ +-----------+Data Flow:
I/O Device ----[DMA Controller]----> Main Memory (No CPU needed during transfer)
Advantages of DMA
- CPU is free to execute other instructions during data transfer.
- Faster data transfer compared to programmed I/O or interrupt-driven I/O.
- Suitable for high-speed, bulk data transfers (e.g., disk to memory).
Summary
DMA allows I/O devices to transfer data directly to/from memory by temporarily taking control of the system bus, with the CPU only involved at the start (initialization) and end (interrupt) of the transfer.
- The CPU programs the DMA controller by providing:
- 65 marksFile types and characteristicsHideAnswer
What are different types of file? Describe the sequential and random access of files. [5]
Types of Files, Sequential and Random Access
Types of Files
Files can be classified based on their nature and access method:
-
Text Files - Store data as human-readable characters (ASCII/Unicode). Each line ends with a newline character. Example:
.txt,.csv -
Binary Files - Store data in binary format (as bytes), not human-readable. Example:
.exe,.jpg,.mp3 -
Sequential Files - Records are stored and accessed one after another in order.
-
Random Access Files (Direct Access Files) - Records can be accessed directly at any position without reading preceding records.
-
Index Sequential Files - Combination of sequential and direct access; uses an index to locate records.
Sequential Access of Files
In sequential access, data is read or written in order from the beginning to the end of the file. To reach a particular record, all preceding records must be read first.
Characteristics:
- Simple to implement
- Suitable for batch processing (e.g., payroll, billing)
- Slow for searching a specific record
- Pointer moves only forward (one record at a time)
Operations:
Operation Description open()Opens file at the beginning read()Reads next record in sequence write()Writes next record in sequence close()Closes the file Example (in C-like pseudocode):
FILE *fp = fopen("data.txt", "r"); while (!feof(fp)) { fscanf(fp, "%s", record); // process record } fclose(fp);Diagram:
[Record 1] --> [Record 2] --> [Record 3] --> [Record 4] --> EOF Read 1st Read 2nd Read 3rd Read 4th
Random Access of Files
In random access (direct access), any record can be read or written directly by specifying its position (offset) in the file, without reading preceding records.
Characteristics:
- Faster access to specific records
- Suitable for databases and real-time systems
- Uses
seek()function to move file pointer to any position - Requires knowledge of record size for offset calculation
Key Functions:
Function Description fseek(fp, offset, origin)Moves file pointer to a specific position ftell(fp)Returns current position of file pointer rewind(fp)Moves file pointer back to the beginning fseek()Origins:SEEK_SET- Beginning of fileSEEK_CUR- Current positionSEEK_END- End of file
Example (in C):
FILE *fp = fopen("data.bin", "rb"); int recordSize = sizeof(struct Record); int recordNo = 3; // Access 3rd record directly fseek(fp, (recordNo - 1) * recordSize, SEEK_SET); fread(&record, recordSize, 1, fp); fclose(fp);Diagram:
[Record 1] [Record 2] [Record 3] [Record 4] [Record 5] ^ | Direct jump using fseek()
Comparison Table
Feature Sequential Access Random Access Access method One by one in order Directly by position Speed Slow for specific record Fast for specific record Complexity Simple Slightly complex Use case Batch processing Databases, real-time File pointer Moves only forward Can move anywhere -
- 75 marks5-state process modelHideAnswer
Draw and describe the 5-state process model. [5]
--- State Description -------------------- New Process has just been created but has not yet been admitted to the pool of executable processes Ready Process is prepared to execute and is waiting to be assigned to a CPU Running Process is...
- 85 marksDeadlock definitionHideAnswer
what is deadlock? What ate necessary conditions for deadlock? Explain. [5]
Deadlock
Definition
A deadlock is a situation in a multiprogramming environment where a set of processes are blocked permanently because each process in the set is waiting for a resource that is held by another process in the same set. None of the processes can proceed, and they wait indefinitely.
Example: Process P1 holds Resource R1 and waits for R2, while Process P2 holds R2 and waits for R1. Neither can proceed.
Necessary Conditions for Deadlock (Coffman Conditions)
Deadlock can occur if and only if all four of the following conditions hold simultaneously:
1. Mutual Exclusion
- At least one resource must be held in a non-shareable mode.
- Only one process can use the resource at a time.
- If another process requests that resource, it must wait until the resource is released.
Example: A printer can be used by only one process at a time.
2. Hold and Wait
- A process must be holding at least one resource and waiting to acquire additional resources that are currently held by other processes.
- The process does not release the resources it already holds while waiting.
Example: P1 holds R1 and is waiting for R2.
3. No Preemption
- Resources cannot be forcibly taken away from a process.
- A resource can only be released voluntarily by the process holding it, after it has completed its task.
Example: A process holding a file lock cannot be forced to release it.
4. Circular Wait
- A set of processes {P0, P1, P2, ..., Pn} must exist such that:
- P0 is waiting for a resource held by P1
- P1 is waiting for a resource held by P2
- ...
- Pn is waiting for a resource held by P0
- This forms a circular chain of waiting processes.
Example: P1 → waits for R2 (held by P2) → waits for R1 (held by P1)
Summary Table
Condition Description Mutual Exclusion Resource held in non-shareable mode Hold and Wait Process holds resource while waiting for more No Preemption Resources cannot be forcibly taken Circular Wait Circular chain of processes waiting for resources Note: All four conditions must hold simultaneously for deadlock to occur. Preventing even one condition is sufficient to prevent deadlock.
- 95 marksThread definition and characteristicsHideAnswer
What is thread? Explain user level thread and kernel level thread. [5]
Thread, User Level Thread, and Kernel Level Thread
What is a Thread?
A thread is the smallest unit of CPU execution within a process. It is also called a lightweight process (LWP). A thread shares the code section, data section, and OS resources (like open files and signals) with other threads belonging to the same process, but has its own:
- Thread ID
- Program counter (PC)
- Register set
- Stack
A process can have multiple threads running concurrently, which improves performance and responsiveness.
User Level Threads (ULT)
User level threads are managed entirely by a user-space thread library (e.g., POSIX Pthreads) without kernel involvement.
Characteristics:
- The kernel is not aware of the existence of these threads.
- Thread management (creation, scheduling, synchronization) is done by the user-level library.
- From the kernel's perspective, the entire process appears as a single-threaded process.
Advantages:
- Thread switching does not require kernel mode, so it is faster.
- Can be implemented on any OS, even those that do not support threads.
- More portable and flexible scheduling.
Disadvantages:
- If one thread makes a blocking system call, the entire process is blocked.
- Cannot take advantage of multiprocessor systems (all threads map to one kernel thread).
Kernel Level Threads (KLT)
Kernel level threads are managed directly by the operating system kernel.
Characteristics:
- The kernel maintains information about each thread.
- Thread creation, scheduling, and management are performed by the kernel.
- Each user thread maps to a kernel thread.
Advantages:
- If one thread is blocked, the kernel can schedule another thread of the same process.
- Can run on multiple processors simultaneously (true parallelism).
- Better support for multiprocessor environments.
Disadvantages:
- Thread switching requires a mode switch to kernel, making it slower than ULT.
- More overhead in thread management.
Comparison Table
Feature User Level Thread Kernel Level Thread Managed by User-space library Operating System Kernel Kernel awareness Not aware Fully aware Speed Faster (no mode switch) Slower (mode switch needed) Blocking Blocks entire process Only the calling thread blocks Multiprocessor support No Yes Example POSIX Pthreads (user mode) Windows threads, Linux threads
Note: Many modern operating systems use a combined (hybrid) approach where multiple user threads are mapped to multiple kernel threads to get the benefits of both models.
- 105 marksNumericalBitmap based free space managementHideAnswer
A 2 GB hard disk has 2 KB block size, calculate the size of bitmap for bitmap based free space management. [5]
Parameter Value ------------------ Disk size 2 GB Block size 2 KB In bitmap free space management, every disk block is represented by exactly 1 bit (1 = allocated, 0 = free). So the bitmap size in bits equals the total number of blocks. ...
- 115 marksTypes of operating systemsHideAnswer
What is an operating system? Differentiate between time sharing and real time operating system. [5]
An Operating System (OS) is system software that acts as an intermediary between the user and the computer hardware. It manages all hardware resources and provides a platform for application programs to run. Key functions of an OS includ...
- 125 marksNumericalRound Robin schedulingHideAnswer
CPU Scheduling Analysis
Consider the following set of processes, with the length of CPU burst time given in milliseconds. The processes are assumed to have arrived in the order A, B, C and D all at time 0. What is the turnaround time and waiting time for the scheduling algorithms, RR (quantum = 3) and Priority Algorithm.
Process CPU Burst Priority A 8 3 B 9 1 (Lowest) C 10 2 D 6 4 (Highest) [5]
CPU Scheduling: RR (q=3) and Priority
STEP 1 - Given Data
Process CPU Burst Priority A 8 3 B 9 1 (Lowest) C 10 2 D 6 4 (Highest) All arrive at time 0, in order A, B, C, D.
Formulas: $TAT = CT - AT$, $WT = TAT - Burst$.
STEP 2 - Solve
1. Round Robin (Quantum = 3)
Ready queue starts: A, B, C, D. A process that still has remaining burst rejoins the tail of the queue after its slice.
Tracing execution (remaining bursts A=8, B=9, C=10, D=6):
Slot Proc Range Remaining after 1 A 0-3 A=5 2 B 3-6 B=6 3 C 6-9 C=7 4 D 9-12 D=3 5 A 12-15 A=2 6 B 15-18 B=3 7 C 18-21 C=4 8 D 21-24 D=0 ✓ 9 A 24-26 A=0 ✓ 10 B 26-29 B=0 ✓ 11 C 29-32 C=1 12 C 32-33 C=0 ✓ Gantt:
| A | B | C | D | A | B | C | D | A | B | C | C | 0 3 6 9 12 15 18 21 24 26 29 32 33Process Burst CT TAT WT A 8 26 26 18 B 9 29 29 20 C 10 33 33 23 D 6 24 24 18 $$\text{Avg TAT} = \frac{26+29+33+24}{4} = \frac{112}{4} = 28 \text{ ms}$$ $$\text{Avg WT} = \frac{18+20+23+18}{4} = \frac{79}{4} = 19.75 \text{ ms}$$
2. Priority Scheduling (Non-Preemptive)
Higher number = higher priority. Execution order: D (4) → A (3) → C (2) → B (1)
Gantt:
| D | A | C | B | 0 6 14 24 33Process Burst CT TAT WT D 6 6 6 0 A 8 14 14 6 C 10 24 24 14 B 9 33 33 24 $$\text{Avg TAT} = \frac{6+14+24+33}{4} = \frac{77}{4} = 19.25 \text{ ms}$$ $$\text{Avg WT} = \frac{0+6+14+24}{4} = \frac{44}{4} = 11 \text{ ms}$$
Summary
Algorithm Avg TAT Avg WT RR (q=3) 28 ms 19.75 ms Priority 19.25 ms 11 ms