ITM 301

Operating System

TU BITM · Semester 5 · BITM curriculum and programme regulation

Requirement
required
Credits
3
Practice sets
5 sets

Practice sets and model questions

5 complete syllabus-aligned practice examinations with model-style questions and step-by-step solutions. Independently prepared by Paper Khoj, not issued by TU.

practice sets loaded.

Practice Set 1

Report problem

PAPER KHOJ

Practice Examination — Set 1

For BITM · Semester 5

Based on the prescribed TU Faculty of Management syllabus and examination structure

Independently prepared by Paper Khoj. This is not an official Tribhuvan University or Dean's Office question paper.

Course: ITM 301 · Operating System

Level: Bachelor of Information Technology Management (BITM) · Semester 5

Full Marks: 60

Time: 3 hrs.

Candidates are required to give their answers in their own words as far as practicable. The figures in the margin indicate full marks.

Group 'A'

Brief Answer Questions. Attempt all questions.

[5 × 2 = 10]
  1. [2]

    Distinguish between Monolithic Kernel and Microkernel architectures with an example of each.

    View model answerHide model answer

    Monolithic Kernel vs. Microkernel:

    • Monolithic Kernel: All core OS services (VFS, IPC, device drivers, network stack, memory management) run in privileged kernel space within a single shared address space (e.g. Linux, Traditional Unix). High performance, but a driver crash can crash the entire OS.
    • Microkernel: Only bare minimum primitives (low-level memory allocation, thread scheduling, basic IPC) run in kernel space; drivers and file systems execute as user-space daemons communicating via message passing (e.g. QNX, Minix, Mach). High stability and modularity with modest IPC context-switch overhead.
  2. [2]

    What is a Process Control Block (PCB)? List four essential fields contained in it.

    View model answerHide model answer

    Process Control Block (PCB):

    A PCB (or task struct) is a kernel data structure representing an execution instance of a process.

    1. Process ID (PID) and State: Current state (New, Ready, Running, Waiting, Terminated).
    2. Program Counter (PC): Memory address of the next machine instruction to execute.
    3. CPU Registers: Accumulators, index registers, stack pointers saved during context switches.
    4. Memory Management Information: Page tables, base/limit registers, segment tables.
  3. [2]

    What is a Context Switch and what causes context switch overhead?

    View model answerHide model answer

    Context Switch & Overhead:

    A context switch is the mechanism of saving the execution state (registers, PC) of the currently running process into its PCB and restoring the state of another scheduled process.

    • Overhead Sources: Pure non-productive CPU cycles spent copying registers, flushing the Translation Lookaside Buffer (TLB), invalidating CPU L1/L2 data caches, and updating kernel dispatch tables.
  4. [2]

    Distinguish between Preemptive and Non-Preemptive scheduling.

    View model answerHide model answer

    Preemptive vs. Non-Preemptive Scheduling:

    • Preemptive: The OS scheduler can forcibly interrupt and suspend a currently running process before its burst completes upon timer interrupt or arrival of a higher-priority task (e.g. Round Robin, SRTF, Linux CFS).
    • Non-Preemptive: Once allocated CPU time, a process retains control until it voluntarily yields by issuing an I/O wait request or terminating (e.g. FCFS, Non-preemptive SJF).
  5. [2]

    What is a Zombie process vs. an Orphan process in Unix systems?

    View model answerHide model answer

    Zombie vs. Orphan Processes:

    • Zombie Process: A process that has completed execution but remains in the process table because its parent has not yet read its exit status code via wait() / waitpid().
    • Orphan Process: A running process whose parent process terminated before it; it is immediately adopted by the root init/systemd process (PID 1), which reaps it upon termination.

Group 'B'

Descriptive Answer Questions. Attempt any SIX questions.

[6 × 5 = 30]
  1. [5]

    Consider four processes arriving in order P1, P2, P3, P4 with arrival times and CPU burst times given as:

    • P1: Arrival = 0, Burst = 8
    • P2: Arrival = 1, Burst = 4
    • P3: Arrival = 2, Burst = 9
    • P4: Arrival = 3, Burst = 5 Draw the Gantt chart and calculate the Average Waiting Time and Average Turnaround Time using: (a) First-Come, First-Served (FCFS), and (b) Shortest Remaining Time First (SRTF).
    View model answerHide model answer

    CPU Scheduling Analysis:

    (a) FCFS Scheduling:

    Execution order follows arrival: P1 (0 to 8), P2 (8 to 12), P3 (12 to 21), P4 (21 to 26).

    Process Arrival (ATAT) Burst (BTBT) Completion (CTCT) Turnaround (TAT=CT−ATTAT = CT - AT) Waiting (WT=TAT−BTWT = TAT - BT)
    P1 0 8 8 8−0=88 - 0 = 8 8−8=08 - 8 = 0
    P2 1 4 12 12−1=1112 - 1 = 11 11−4=711 - 4 = 7
    P3 2 9 21 21−2=1921 - 2 = 19 19−9=1019 - 9 = 10
    P4 3 5 26 26−3=2326 - 3 = 23 23−5=1823 - 5 = 18
    • Average Turnaround Time: 8+11+19+234=614=15.25 ms\frac{8 + 11 + 19 + 23}{4} = \frac{61}{4} = \mathbf{15.25\text{ ms}}
    • Average Waiting Time: 0+7+10+184=354=8.75 ms\frac{0 + 7 + 10 + 18}{4} = \frac{35}{4} = \mathbf{8.75\text{ ms}}

    (b) SRTF (Preemptive SJF):

    • At t=0t = 0: P1 starts (remaining: 8).
    • At t=1t = 1: P2 arrives with BT=4BT=4; P1 has 7 remaining. Since 4<74 < 7, preempt P1, run P2.
    • At t=2t = 2: P3 arrives (BT=9BT=9). P2 has 3 remaining. Continue P2.
    • At t=3t = 3: P4 arrives (BT=5BT=5). P2 has 2 remaining. Continue P2.
    • At t=5t = 5: P2 finishes (CT=5CT=5). Remaining: P1(7), P4(5), P3(9). Smallest is P4   ⟹  \implies run P4.
    • At t=10t = 10: P4 finishes (CT=10CT=10). Remaining: P1(7), P3(9). Run P1.
    • At t=17t = 17: P1 finishes (CT=17CT=17). Run P3.
    • At t=26t = 26: P3 finishes (CT=26CT=26).
    Process Arrival Burst Completion (CTCT) TAT=CT−ATTAT = CT - AT WT=TAT−BTWT = TAT - BT
    P1 0 8 17 17−0=1717 - 0 = 17 17−8=917 - 8 = 9
    P2 1 4 5 5−1=45 - 1 = 4 4−4=04 - 4 = 0
    P3 2 9 26 26−2=2426 - 2 = 24 24−9=1524 - 9 = 15
    P4 3 5 10 10−3=710 - 3 = 7 7−5=27 - 5 = 2
    • Average Turnaround Time (SRTF): 17+4+24+74=524=13.00 ms\frac{17 + 4 + 24 + 7}{4} = \frac{52}{4} = \mathbf{13.00\text{ ms}}
    • Average Waiting Time (SRTF): 9+0+15+24=264=6.50 ms\frac{9 + 0 + 15 + 2}{4} = \frac{26}{4} = \mathbf{6.50\text{ ms}}
  2. [5]

    Explain the difference between User-Level Threads (ULT) and Kernel-Level Threads (KLT). Detail the three multithreading models (Many-to-One, One-to-One, Many-to-Many).

    View model answerHide model answer

    User-Level Threads (ULT) vs. Kernel-Level Threads (KLT):

    • ULT: Managed entirely by a user-space thread library without kernel awareness. Switching is fast (O(1)O(1)) with zero kernel traps, but if one thread blocks on system I/O, the entire process stalls.
    • KLT: Supported and scheduled directly by the OS kernel. If a thread blocks, the kernel can schedule another thread of the same process. Context switching is heavier.

    Three Multithreading Mapping Models:

    1. Many-to-One Model: Many ULTs mapped to a single KLT. Inability to leverage multi-core processors; one blocking call stalls all threads.
    2. One-to-One Model (Linux/Windows): Each ULT maps to a dedicated KLT. True multi-core concurrency; overhead scales with thread count.
    3. Many-to-Many Model: Multiplexes MM user threads over NN kernel threads (M≥NM \ge N). Combines lightweight user management with kernel concurrency.
  3. [5]

    Explain the Inter-Process Communication (IPC) mechanisms in modern operating systems: Shared Memory vs. Message Passing.

    View model answerHide model answer

    Shared Memory vs. Message Passing:

    Dimension Shared Memory Message Passing
    Mechanism Operating system establishes a shared physical memory segment mapped into address spaces of both processes. Processes exchange packets/messages via kernel system calls (send(), receive()).
    Speed Extremely fast; memory accesses occur at hardware RAM speeds without kernel intervention. Slower; requires kernel mode transitions, context switching, and buffer copies.
    Synchronization Processes must manage race conditions using semaphores/mutexes. Synchronization is handled implicitly by the OS message queue.
    Distributed Systems Difficult across distinct physical hosts without specialized hardware. Ideal for distributed network nodes (sockets, RPC).
  4. [5]

    What is a System Call? Describe the step-by-step sequence of events that occurs when a user program invokes read() to access data from disk.

    View model answerHide model answer

    System Call Execution Flow (read()):

    A system call provides the programmatic interface between user applications and privileged OS kernel services.

    Step-by-Step Transition Flow:

    1. Invocation: User program calls standard C library wrapper read(fd, buffer, count).
    2. Setup: Library pushes system call number (e.g. __NR_read) into a CPU register (e.g., rax) and loads parameters into registers.
    3. Trap to Kernel: Executes software trap instruction (syscall / int 0x80), switching CPU privilege from User Mode (Ring 3) to Kernel Mode (Ring 0).
    4. Dispatcher: Kernel looks up the system call number in the System Call Table and invokes sys_read().
    5. I/O Execution: Kernel verifies buffer permissions, calls VFS, triggers disk DMA transfer, and places the calling thread in I/O wait state.
    6. Return: When data arrives in memory, CPU registers are restored, mode switches back to User Mode, and control returns with byte count.
  5. [5]

    Explain the Round Robin (RR) CPU scheduling algorithm. Discuss how the selection of Time Quantum (qq) affects system performance between FCFS and processor sharing.

    View model answerHide model answer

    Round Robin (RR) Scheduling & Time Quantum (qq):

    Round Robin is a preemptive scheduling algorithm designed for time-sharing systems where the ready queue is treated as a circular FIFO queue. Each process gets a discrete slice of CPU time called a Time Quantum (qq).

    Impact of Quantum Size (qq):

    • If q→∞q \to \infty (Excessively Large): RR degenerates into First-Come, First-Served (FCFS) scheduling. Interactive response times suffer severely.
    • If q→0q \to 0 (Extremely Small): Mimics theoretical Processor Sharing, where each of NN processes appears to run at 1/N1/N-th speed. However, excessive context switches overwhelm the CPU with kernel overhead, degrading actual throughput.
    • Rule of Thumb: qq should be chosen such that approximately 80%80\% of CPU bursts complete within a single quantum (typically 10 - 100 ms).
  6. [5]

    What is Multilevel Feedback Queue (MLFQ) scheduling? How does it prevent process starvation and accommodate both interactive and batch jobs?

    View model answerHide model answer

    Multilevel Feedback Queue (MLFQ):

    MLFQ separates the ready queue into multiple distinct priority levels with varying time quanta (e.g., Queue 0: q=8 msq = 8\text{ ms}, Queue 1: q=16 msq = 16\text{ ms}, Queue 2: FCFS).

    Operational Rules:

    1. New processes enter the highest priority queue (Queue 0).
    2. Demotion: If a process exhausts its full time quantum without releasing CPU, it is demoted to the next lower priority queue (penalizing CPU-bound batch jobs).
    3. Promotion: If a process yields CPU before quantum expiration (interactive I/O-bound jobs), it remains in or is promoted to higher queues.
    4. Starvation Prevention (Priority Boost): Periodically, the scheduler moves all waiting processes to the highest priority queue, ensuring compute-intensive jobs do not starve.

Group 'C'

Comprehensive / Analytical Questions. Attempt all questions.

[2 × 10 = 20]
  1. [10]

    Define the Critical Section Problem. State and explain the three necessary requirements that any valid solution must satisfy. Present Peterson’s Algorithm for two processes, analyze its code line-by-line, and prove that it fulfills Mutual Exclusion, Progress, and Bounded Waiting.

    View model answerHide model answer

    The Critical Section Problem & Peterson’s Solution:

    A critical section is a segment of code where multiple concurrently executing threads access and manipulate shared variables, shared memory, or shared files, creating potential race conditions.


    Three Cardinal Criteria for a Valid Solution:

    1. Mutual Exclusion: If process PiP_i is executing in its critical section, no other process can be executing in its critical section simultaneously.
    2. Progress: If no process is in its critical section and some processes wish to enter, only those processes not in their remainder section can participate in deciding who enters next, and selection cannot be postponed indefinitely.
    3. Bounded Waiting: There must be a bound on the number of times other processes are allowed to enter their critical sections after a process has made a request to enter, before that request is granted (preventing starvation).

    Peterson’s Algorithm (Two Processes: P0P_0 and P1P_1):

    Shared state variables:

    int turn;              // Whose turn it is to enter
    bool flag[2];          // flag[i] == true indicates Pi wants to enter
    

    Process PiP_i Implementation (j=1−ij = 1 - i):

    do {
        flag[i] = true;              // 1. Declare intent to enter
        turn = j;                    // 2. Give preference to other process
        while (flag[j] && turn == j); // 3. Busy-wait while rival wants in and it's rival's turn
    
        // --- CRITICAL SECTION ---
        critical_section();
    
        flag[i] = false;             // 4. Exit section: relinquish interest
    
        // --- REMAINDER SECTION ---
        remainder_section();
    } while (true);
    

    Proof of Compliance:

    1. Mutual Exclusion: For both P0P_0 and P1P_1 to enter simultaneously, both while loop conditions must evaluate to false. That requires turn == 1 and turn == 0 simultaneously, which is logically impossible since turn holds a single scalar integer.
    2. Progress: If PjP_j is not interested, flag[j] == false, so PiP_i enters immediately. If both request simultaneously, turn will be either 0 or 1, allowing exactly one process to pass while the other waits.
    3. Bounded Waiting: When PiP_i exits, it sets flag[i] = false. If it immediately loops back, it sets turn = j, giving PjP_j priority. Thus, PjP_j waits at most one entry cycle.
  2. [10]

    Explain Semaphores and Mutex Locks. Detail the Classic Synchronization Problems: (a) Producer-Consumer with bounded buffer using counting and binary semaphores, and (b) The Dining Philosophers Problem with deadlock prevention.

    View model answerHide model answer

    Synchronization Primitives & Classic Problems:

    • Mutex: Binary locking mechanism providing exclusive access (00 or 11). The locking thread must be the thread that unlocks it.
    • Semaphore: An integer synchronization variable accessed only through atomic operations:
      • wait(S) / P(S): Decrements SS; if S<0S < 0, calling thread blocks.
      • signal(S) / V(S): Increments SS; wakes up one blocked thread.

    (a) Bounded-Buffer Producer-Consumer Solution:

    Buffer size NN. Shared state:

    semaphore mutex = 1;     // Binary semaphore for mutual exclusion on buffer
    semaphore empty = N;     // Counting semaphore: tracks vacant buffer slots
    semaphore full = 0;      // Counting semaphore: tracks populated items
    

    Producer Process:

    do {
        item = produce_item();
        wait(empty);         // Decrement empty slots; wait if buffer full
        wait(mutex);         // Lock buffer access
        insert_item(item);
        signal(mutex);       // Release buffer lock
        signal(full);        // Notify consumer of new item
    } while (true);
    

    Consumer Process:

    do {
        wait(full);          // Wait until at least one item is present
        wait(mutex);         // Lock buffer access
        item = remove_item();
        signal(mutex);       // Release lock
        signal(empty);       // Increment vacant slot count
        consume_item(item);
    } while (true);
    

    (b) Dining Philosophers Problem & Deadlock Prevention:

    5 philosophers seated around a table with 5 chopsticks. Each philosopher needs both left chopstick ii and right chopstick (i+1)%5(i+1)\%5 to eat.

    • Deadlock Condition: If all 5 pick up their left chopstick simultaneously, all right chopsticks are unavailable; all starve waiting forever.

    Deadlock-Free Asymmetric Solution:

    Enforce asymmetric pickup ordering:

    • Odd philosophers pick up Left then Right.
    • Even philosophers pick up Right then Left.
    • Or restrict table occupancy to a maximum of 4 philosophers simultaneously via a counting semaphore initialized to 4.