BIT204 · TU past paper
Operating Systems 2079 question paper
The complete TU 2079 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 marksTypes of operating systemsHideAnswer
What are the different types of operating system? Differentiate between Real time and Batch OS.[10]
Types of Operating Systems and Difference Between Real-Time and Batch OS
Types of Operating Systems
An Operating System (OS) is system software that manages hardware and software resources and provides services to computer programs. Operating systems are classified into the following types:
1. Batch Operating System
- Jobs with similar requirements are grouped (batched) together and executed without user interaction.
- A job scheduler picks jobs from the batch and submits them to the CPU one by one.
- Example: Early IBM mainframe systems, payroll processing.
2. Time-Sharing (Multitasking) Operating System
- CPU time is shared among multiple users/processes simultaneously.
- Each process gets a small time slice (quantum) in a round-robin fashion.
- Provides fast response time and interactive use.
- Example: UNIX, Linux, Windows.
3. Real-Time Operating System (RTOS)
- Designed to process data and respond within a strict, guaranteed time constraint (deadline).
- Used in time-critical applications.
- Example: Air traffic control, medical devices, missile guidance systems, VxWorks.
4. Distributed Operating System
- Manages a group of independent computers and makes them appear as a single system to the user.
- Resources (CPU, memory, storage) are distributed across multiple machines.
- Example: LOCUS, Amoeba.
5. Network Operating System
- Provides features to manage data, users, groups, security, and applications over a network.
- Each machine has its own local OS but can share resources over the network.
- Example: Windows Server, Novell NetWare.
6. Multiprocessor Operating System
- Supports systems with more than one CPU sharing the same memory and I/O devices.
- Increases throughput and reliability.
- Example: Symmetric Multiprocessing (SMP) systems.
7. Embedded Operating System
- Designed to operate on small machines (embedded systems) with limited resources.
- Highly specialized and resource-efficient.
- Example: Android (mobile), FreeRTOS, Windows CE.
8. Mobile Operating System
- Designed specifically for smartphones and tablets.
- Manages mobile hardware such as touchscreen, GPS, camera.
- Example: Android, iOS.
Difference Between Real-Time OS and Batch OS
Basis Real-Time OS (RTOS) Batch OS Definition An OS that processes tasks and produces results within a strict time deadline. An OS that collects jobs into batches and processes them sequentially without user interaction. Response Time Extremely fast and guaranteed (microseconds to milliseconds). Response time is slow and not guaranteed; depends on queue length. User Interaction Minimal or no user interaction during execution; but system reacts to real-world events. No user interaction once the batch is submitted. Deadline Strict deadlines must be met (missing a deadline can cause system failure). No concept of strict deadlines; jobs are processed as resources become available. Priority Tasks are assigned priorities; high-priority tasks preempt lower ones. Jobs are processed in the order they are batched (FCFS or similar). Scheduling Priority-based, preemptive scheduling is used. Non-preemptive, sequential scheduling is used. Types Hard RTOS (strict deadlines) and Soft RTOS (flexible deadlines). Simple batch and multiprogrammed batch. CPU Utilization CPU utilization may not be maximum; correctness and timing are more important. Aims for maximum CPU utilization. Error Handling Must handle errors immediately and reliably. Errors are reported after job completion; job may be skipped. Applications Medical devices, missile systems, air traffic control, robotics. Payroll processing, bank statements, weather forecasting data processing. Complexity More complex due to timing constraints and event-driven nature. Relatively simpler to design and implement. Example Systems VxWorks, FreeRTOS, QNX. Early IBM OS/360, simple mainframe batch systems.
Summary
Operating systems are classified based on how they manage processes, respond to users, and handle time constraints. Batch OS focuses on throughput and sequential job processing with no real-time constraints, while Real-Time OS focuses on correctness within strict time limits, making it essential for safety-critical and time-sensitive applications.
- 210 marksSystem call process and mechanismHideAnswer
What is kernel? Explain the process of system call with suitable diagram.[10]
Kernel and System Call Process
What is Kernel? [3 marks]
The kernel is the core component of an operating system that acts as a bridge between application programs and the computer hardware. It is the first program loaded into memory when the computer starts (after the bootloader) and remains in memory throughout the entire session.
Key Characteristics of the Kernel:
- It runs in privileged mode (also called kernel mode or supervisor mode), which gives it unrestricted access to all hardware resources.
- It manages system resources such as CPU, memory, I/O devices, and file systems.
- It provides a protected environment so that user programs cannot directly access hardware.
Functions of the Kernel:
Function Description Process Management Creates, schedules, and terminates processes Memory Management Allocates and deallocates memory to processes Device Management Controls hardware devices via device drivers File System Management Manages files and directories on storage Inter-Process Communication Allows processes to communicate with each other System Call Interface Provides an interface for user programs to request services Types of Kernel:
- Monolithic Kernel - All OS services run in kernel space (e.g., Linux, Unix)
- Microkernel - Only essential services run in kernel space (e.g., Minix)
- Hybrid Kernel - Combination of monolithic and microkernel (e.g., Windows NT)
System Call [7 marks]
Definition:
A system call is a programmatic way in which a user-level program requests a service from the operating system kernel. It provides the interface between a running process (user mode) and the operating system.
System calls are the only legal entry points into the kernel. When a user program needs to perform a privileged operation (such as reading a file, creating a process, or allocating memory), it must do so through a system call.
Types of System Calls:
- Process Control -
fork(),exit(),wait() - File Management -
open(),read(),write(),close() - Device Management -
ioctl(),read(),write() - Information Maintenance -
getpid(),alarm(),sleep() - Communication -
pipe(),shmget(),mmap()
Process of System Call (Step-by-Step):
USER SPACE KERNEL SPACE ----------- ------------ [User Program] | | 1. Calls library function v [Library / API] e.g., printf() | | 2. Prepares parameters, | places system call | number in register v [TRAP / INT instruction] (Software Interrupt) | |-------- MODE SWITCH --------> [Kernel Mode Activated] | | 3. Hardware saves | CPU state (registers, | PC, flags) v [Trap Handler / Interrupt Vector Table] | | 4. Identifies system | call number v [System Call Dispatcher / System Call Table] | | 5. Calls appropriate | kernel routine v [Kernel Service Routine] e.g., sys_write() | | 6. Executes the | requested service | | 7. Places return value | in register | <------- MODE SWITCH ---------- | [Return to User Mode] [Kernel Mode Ends] | | 8. Library function | retrieves return value v [User Program Continues]
Detailed Steps Explained:
Step 1: User Program Makes a Request
- The user program calls a high-level library function (e.g.,
read()in C). - This library function is part of the API (Application Programming Interface).
Step 2: Prepare for System Call
- The library function places the system call number into a specific CPU register (e.g., register
EAXin x86). - Any arguments/parameters are placed in other registers or on the stack.
Step 3: Execute TRAP Instruction
- The library executes a special instruction called TRAP or INT (software interrupt), e.g.,
INT 0x80in Linux x86. - This causes a mode switch from user mode to kernel mode.
- The CPU saves the current state (program counter, registers, flags) onto the kernel stack.
Step 4: Trap Handler Invoked
- The hardware transfers control to a fixed memory address -- the trap handler (defined in the interrupt vector table).
- The trap handler verifies the system call number.
Step 5: System Call Dispatcher
- The dispatcher uses the system call number as an index into the system call table.
- The system call table is an array of function pointers pointing to kernel service routines.
Step 6: Kernel Service Routine Executes
- The appropriate kernel routine (e.g.,
sys_read()) executes with full hardware privileges. - It performs the requested operation (reads from disk, allocates memory, etc.).
Step 7: Return from Kernel
- The return value (success/error code) is placed in a register.
- The kernel executes a return-from-trap instruction (e.g.,
IRET). - The CPU restores the saved state and switches back to user mode.
Step 8: User Program Resumes
- The library function retrieves the return value from the register.
- Control returns to the user program, which continues execution.
Diagram Summary:
+------------------+ System Call +------------------+ | | -----------------------> | | | USER PROCESS | | KERNEL | | (User Mode) | <----------------------- | (Kernel Mode) | +------------------+ Return Value +------------------+ | | | 1. call read() | v | +------------------+ | | Library / API | 2. system call number -> register | | (libc wrapper) | 3. TRAP / INT 0x80 | +---------+--------+ | | v | +---------------------------+ +------------------------->| 4. Trap handler | | 5. System call dispatcher| | (system call table) | | 6. sys_read() executes | +-------------+-------------+ | 7. IRET, restore state, back to user mode
Conclusion
The kernel is the core of the operating system: it always resides in memory, runs in privileged mode, and owns the hardware. A user program can never touch that hardware directly, so a system call is the controlled doorway between the two worlds. The library wrapper loads the call number and arguments, a TRAP instruction switches the CPU into kernel mode, the dispatcher looks the number up in the system call table, the kernel routine does the work with full privilege, and a return-from-trap puts the CPU back in user mode with the result in a register. This mode switch is what keeps one process from corrupting another or the operating system itself.
- 310 marksNumericalBanker's AlgorithmHideAnswer
Resource Allocation Graph and Deadlock Analysis
A Resource Allocation Graph is a directed graph used to model and detect deadlocks in a system. Components: - Process nodes $P = {P1, P2, \dots, Pn}$ drawn as circles. - Resource nodes $R = {R1, R2, \dots, Rm}$ drawn as rectangles, w...
- 45 marksDefinition and purpose of operating systemHideAnswer
What is an OS? Explain 3-state model of process with neat and clean diagram. [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: -...
- 55 marksLock variable solutionHideAnswer
What is race condition? Explain critical problem solution using lock variable. [5]
A race condition occurs when two or more processes access shared data concurrently, and the final result depends on the order or timing of their execution. Because the processes "race" against each other, the outcome is unpredictable and...
- 65 marksMemory compactionHideAnswer
What is memory compaction? Explain best fit memory allocation with suitable example. [5]
Memory Compaction and Best Fit Memory Allocation
Memory Compaction
Memory compaction is a memory management technique used to overcome the problem of external fragmentation. When processes are loaded and removed from memory over time, free memory becomes scattered in small, non-contiguous blocks. Even if the total free memory is sufficient to accommodate a new process, no single contiguous block may be large enough.
In compaction, the OS shuffles all occupied memory partitions together (toward one end of memory), merging all the scattered free holes into one large contiguous free block.
Key Points:
- Requires dynamic relocation (base register support)
- It is time-consuming and costly in terms of CPU overhead
- Not always possible if relocation cannot be done at runtime
Before Compaction: After Compaction: | P1 (20KB) | | P1 (20KB) | | Free (10KB)| | P2 (15KB) | | P2 (15KB) | ----> | P3 (5KB) | | Free (8KB) | | Free (33KB)| | P3 (5KB) | | | | Free (15KB)| | |
Best Fit Memory Allocation
Best Fit is a contiguous memory allocation strategy in which the OS searches the entire list of free memory holes and allocates the smallest hole that is large enough to satisfy the process's memory request.
Idea:
Allocate the hole that leaves the least leftover free space after allocation.
Advantages:
- Minimizes wasted space in each individual allocation
- Leaves larger holes available for bigger future requests
Disadvantages:
- Slower -- must search the entire free list every time
- Tends to create many tiny, unusable leftover fragments (small holes that are too small for any process) -- leading to external fragmentation
Example
Free Memory Holes (initially):
Hole Size H1 100 KB H2 500 KB H3 200 KB H4 300 KB H5 50 KB Process Requests:
Process Memory Required P1 212 KB P2 417 KB P3 112 KB
Step 1: Allocate P1 (212 KB)
Search all holes for the smallest hole >= 212 KB:
- H1 = 100 KB -- too small
- H2 = 500 KB -- fits, leftover = 288 KB
- H3 = 200 KB -- too small
- H4 = 300 KB -- fits, leftover = 88 KB <-- smallest leftover
- H5 = 50 KB -- too small
Best Fit: H4 (300 KB) Remaining in H4 = 300 - 212 = 88 KB
Step 2: Allocate P2 (417 KB)
Updated holes: H1=100, H2=500, H3=200, H4=88, H5=50
- H2 = 500 KB -- fits, leftover = 83 KB <-- only hole large enough
Best Fit: H2 (500 KB) Remaining in H2 = 500 - 417 = 83 KB
Step 3: Allocate P3 (112 KB)
Updated holes: H1=100, H2=83, H3=200, H4=88, H5=50
- H1 = 100 KB -- too small
- H2 = 83 KB -- too small
- H3 = 200 KB -- fits, leftover = 88 KB <-- smallest leftover
- H4 = 88 KB -- too small
- H5 = 50 KB -- too small
Best Fit: H3 (200 KB) Remaining in H3 = 200 - 112 = 88 KB
Final State of Memory:
Hole Original Remaining H1 100 KB 100 KB (unused) H2 500 KB 83 KB (leftover) H3 200 KB 88 KB (leftover) H4 300 KB 88 KB (leftover) H5 50 KB 50 KB (unused) Notice that best fit leaves behind many small leftover fragments, which is its main drawback despite minimizing waste per allocation.
- 75 marksRAID definition and levelsHideAnswer
What is RAID? Explain Level-2 and Level-3 RAID. [5]
RAID (Redundant Array of Independent Disks) is a data storage technology that combines multiple physical disk drives into a single logical unit to achieve one or more of the following goals: - Improved performance (through parallelism/st...
- 85 marksThread definition and characteristicsHideAnswer
How threads differ from processes? Explain user level thread and kernel level thread. [5]
--- Aspect Process Thread --------- Definition An independent program in execution with its own address space A lightweight unit of execution within a process Memory Has its own separate memory space Shares memory (code, data, heap) with...
- 95 marksNumericalOptimal page replacement algorithmHideAnswer
Consider the following page reference string: 3,2,1,3,4,2,8,9,7,4,2,9,8,3. Calculate the total number of page faults for Optimal and LRU page replacement algorithms using a 4 page frame. [5]
- Reference string: 3, 2, 1, 3, 4, 2, 8, 9, 7, 4, 2, 9, 8, 3 (14 references) - Frames = 4 --- Replace the page whose next use is furthest in the future. Step Page Frames after the reference Fault? Replacement reasoning ------------------...
- 105 marksTranslation Lookaside BufferHideAnswer
What is TLB? Explain the importance of TLB in conversion of logical address to physical address. [5]
Translation Lookaside Buffer (TLB)
Definition
A Translation Lookaside Buffer (TLB) is a small, fast hardware cache (associative memory) that stores recently used page table entries. It acts as a high-speed lookup table used by the Memory Management Unit (MMU) to speed up the translation of logical (virtual) addresses to physical addresses.
Note: No specific reference notes were found for this topic; the answer is based on standard OS theory as taught in BSc CSIT curriculum.
Structure of TLB
Each entry in the TLB contains:
Page Number Frame Number p f The TLB is implemented using associative memory, meaning all entries are searched simultaneously (in parallel), making lookup extremely fast.
Importance of TLB in Logical to Physical Address Conversion
Without TLB, every memory access requires two memory accesses:
- One to fetch the page table entry (from main memory)
- One to access the actual data/instruction
TLB eliminates this overhead in most cases.
Step-by-Step Address Translation with TLB
Logical Address = (Page Number p, Offset d) | Search TLB / \ TLB Hit TLB Miss | | Get frame f Access Page Table | (in main memory) | | | Get frame f | Update TLB | | +--------+--------+ | Physical Address = (f, d) | Access MemoryCase 1: TLB Hit
- The page number
pis found in the TLB. - The corresponding frame number
fis retrieved directly. - Physical address =
f * page_size + d - Only one memory access is needed (for actual data).
Case 2: TLB Miss
- The page number
pis not found in the TLB. - The page table in main memory is accessed to find frame
f. - The entry
(p, f)is loaded into TLB for future use. - Physical address is then formed.
- Two memory accesses are needed.
Effective Memory Access Time (EMAT)
$$EMAT = \alpha \times (T_{TLB} + T_m) + (1 - \alpha) \times (T_{TLB} + 2T_m)$$
Where:
- $\alpha$ = TLB hit ratio
- $T_{TLB}$ = TLB access time
- $T_m$ = Main memory access time
A high hit ratio (typically 90-99%) means most accesses are fast, greatly reducing average memory access time.
Summary of Importance
Point Explanation Speed Avoids slow page table lookup in main memory on a hit Efficiency Reduces average memory access time significantly Transparency Works automatically without programmer involvement Locality Exploits temporal/spatial locality of memory references In conclusion, TLB is a critical hardware component that makes paged memory systems practical and efficient by caching frequently used address translations.
- 115 marksNumericalFile Allocation TableHideAnswer
Consider 500 GB hard drive with 5 KB block size. Calculate the size of the file allocation table if entry for each block needs 4 bytes. [5]
Parameter Value ------------------ Hard drive size 500 GB Block size 5 KB FAT entry size 4 bytes per block --- $$500 \text{ GB} = 500 \times 1024 \times 1024 \text{ KB} = 524{,}288{,}000 \text{ KB}$$ Each block requires exactly one FAT e...
- 125 marksDMA working mechanismHideAnswer
Explain the working mechanism of DMA. [5]
DMA (Direct Memory Access) is a technique that allows I/O devices to transfer data directly to/from main memory without involving the CPU for each byte/word of the transfer. A dedicated hardware unit called the DMA Controller manages thi...