2078

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.

Past Papers2082208020792078

Tap a question to open its answer.

  1. 110 marksNumericalDisk scheduling algorithmsAnswer

    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...
  2. 210 marksProducer consumer problem with semaphoreAnswer

    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...

  3. 310 marksVirtual memory technique and purposeAnswer

    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...

  4. 45 marksKernel definition and roleAnswer

    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...

  5. 55 marksDMA definition and purposeAnswer

    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

    ComponentRole
    DMA Controller (DMAC)Manages the data transfer independently
    Source Address RegisterHolds the source memory/device address
    Destination Address RegisterHolds the destination memory address
    Count RegisterHolds the number of bytes/words to transfer
    Control RegisterSpecifies 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.

  6. 65 marksFile types and characteristicsAnswer

    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:

    1. Text Files - Store data as human-readable characters (ASCII/Unicode). Each line ends with a newline character. Example: .txt, .csv

    2. Binary Files - Store data in binary format (as bytes), not human-readable. Example: .exe, .jpg, .mp3

    3. Sequential Files - Records are stored and accessed one after another in order.

    4. Random Access Files (Direct Access Files) - Records can be accessed directly at any position without reading preceding records.

    5. 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:

    OperationDescription
    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:

    FunctionDescription
    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 file
    • SEEK_CUR - Current position
    • SEEK_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

    FeatureSequential AccessRandom Access
    Access methodOne by one in orderDirectly by position
    SpeedSlow for specific recordFast for specific record
    ComplexitySimpleSlightly complex
    Use caseBatch processingDatabases, real-time
    File pointerMoves only forwardCan move anywhere
  7. 75 marks5-state process modelAnswer

    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...

  8. 85 marksDeadlock definitionAnswer

    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

    ConditionDescription
    Mutual ExclusionResource held in non-shareable mode
    Hold and WaitProcess holds resource while waiting for more
    No PreemptionResources cannot be forcibly taken
    Circular WaitCircular 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.

  9. 95 marksThread definition and characteristicsAnswer

    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

    FeatureUser Level ThreadKernel Level Thread
    Managed byUser-space libraryOperating System Kernel
    Kernel awarenessNot awareFully aware
    SpeedFaster (no mode switch)Slower (mode switch needed)
    BlockingBlocks entire processOnly the calling thread blocks
    Multiprocessor supportNoYes
    ExamplePOSIX 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.

  10. 105 marksNumericalBitmap based free space managementAnswer

    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. ...

  11. 115 marksTypes of operating systemsAnswer

    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...

  12. 125 marksNumericalRound Robin schedulingAnswer

    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.

    ProcessCPU BurstPriority
    A83
    B91 (Lowest)
    C102
    D64 (Highest)

    [5]

    CPU Scheduling: RR (q=3) and Priority

    STEP 1 - Given Data

    ProcessCPU BurstPriority
    A83
    B91 (Lowest)
    C102
    D64 (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):

    SlotProcRangeRemaining after
    1A0-3A=5
    2B3-6B=6
    3C6-9C=7
    4D9-12D=3
    5A12-15A=2
    6B15-18B=3
    7C18-21C=4
    8D21-24D=0 ✓
    9A24-26A=0 ✓
    10B26-29B=0 ✓
    11C29-32C=1
    12C32-33C=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  33
    
    ProcessBurstCTTATWT
    A8262618
    B9292920
    C10333323
    D6242418

    $$\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  33
    
    ProcessBurstCTTATWT
    D6660
    A814146
    C10242414
    B9333324

    $$\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

    AlgorithmAvg TATAvg WT
    RR (q=3)28 ms19.75 ms
    Priority19.25 ms11 ms