QB Solutions
QB Solutions
Syllabus :
Module-3 ProcessCoordination (Excluding IAT-1 portion)
Introduction to Deadlocks; System Model, Deadlock Characterization; Deadlock Detection and
Recovery; Deadlock Prevention; Deadlock Avoidance.
Module-4 Memory Management
Basic Concepts of Memory Management; Swapping; Contiguous Memory Allocation; Paging;
Structure of Page Table; Segmentation; Basic Concepts of Virtual Memory; Demand Paging,
Copyon Write; Page Replacement Algorithms; Thrashing. Module-5 Storage Management (Till
allocation methods)
Basic Concepts of File System; File Access Methods; Directory Structure; File-System
Implementation; Allocation Methods;
Question Bank:
Module-3 ProcessCoordination For 2 marks :
1. Describe producer consumer problem.
This is usually solved using semaphores or mutex locks to avoid race conditions and deadlocks.
2. Describe RAG. Draw a simple RAG illustrating deadlock with 2 processes and 2 resources.
A Resource Allocation Graph (RAG) is a directed graph used to represent the allocation of
resources to processes.
Deadlock causes complete halt, whereas starvation causes unfairness and delay.
7. Explain when wait for graph is used and how different it is from RAG.
A Wait-For Graph (WFG) is derived from a RAG by removing resource nodes and creating direct
edges between processes.
These help determine whether resource allocation is safe or will lead to deadlock.
For 5 marks :
1. What is classic problem of syncronization Bounded-Bufer Problem , Readers and Writers
Problem, Dining-Philosophers Problem.
These are standard synchronization problems used to illustrate process coordination and the use of
semaphores, mutexes, and monitors.
Bounded-Buffer Problem (Producer-Consumer)
Readers-Writers Problem
Solutions:
First Readers-Writers Problem: No reader should be kept waiting unless a writer has the
permission to use the shared object.
Second Readers-Writers Problem: Once a writer is ready, it performs the write ASAP.
Dining-Philosophers Problem
Five philosophers sit at a table with one chopstick between each pair.
Each needs two chopsticks to eat.
Solutions must avoid deadlock and starvation.
Solutions:
2. Consider a system with 5 processes and 3 resource types. At a time following 3 resource
types: A, B and C are allocated as shown.
Processes Allocation Max Available
A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3
Using Banker’s algorithm,
i) Find out the content of need matrix. (1M) ii)
Check if the system is in safe state. (3M) iii) If
it is safe, specify the safe sequence. (1M)
i) Need Matrix = Max - Allocation
P0: 7 4 3
P1: 1 2 2
P2: 6 0 0
P3: 0 1 1
P4: 4 3 1
P1 → P3 → P4 → P0 → P2
[1 Mark]
I. Introduction (1 Mark)
Deadlocks are conditions where processes wait indefinitely for resources. To handle this, two
proactive methods exist:
Prevention: Ensure one or more necessary conditions for deadlock never hold.
Avoidance: Dynamically assess and grant resources only if they don’t lead to deadlock.
1. Mutual Exclusion
o Avoid by making resources shareable if possible.
o Example: Read-only files.
2. Hold and Wait
o Allocate all resources before execution or require release of current resources before
requesting new ones.
o Downside: Poor resource utilization.
3. No Preemption
o If resource request is denied, forcefully release all held resources.
o Retry later with all required resources.
4. Circular Wait
o Impose a strict global ordering of all resource types.
o Processes must request in ascending order.
Banker’s Algorithm:
o Uses Available, Max, Allocation, and Need matrices.
o Checks for a safe sequence before granting a request.
o Only allocates if system remains in a safe state.
Safe State:
o A sequence exists such that every process can complete with the currently available
resources + those held by earlier processes.
I. Introduction (1 Mark)
Detection is used when prevention/avoidance is not enforced. System periodically checks for
circular waits or deadlocks.
Track:
o Available, Allocation, Request for each process.
Algorithm tries to simulate process completion.
If no process can proceed with current Available → deadlock.
Given:
makefile
CopyEdit
Available: [3, 3, 2]
P0: Allocation [0,1,0], Request [7,4,3]
P1: Allocation [2,0,0], Request [1,2,2]
P2: Allocation [3,0,2], Request [6,0,0]
...
A Logical Address (also called Virtual Address) is the address generated by the CPU
during program execution.
A Physical Address is the actual location in the memory unit where data resides.
Logical addresses are translated into physical addresses using a Memory Management
Unit (MMU).
Logical Address Space: The range of addresses generated by a program (visible to the
user).
They differ in execution-time binding; logical addresses are mapped to physical during
execution.
3. Draw diagram showing hardware address protection with base and limit registers.
pgsql
CopyEdit
CPU → Logical Address
|
+---------------+
| Base Register |
+---------------+
|
+----------------------+
| Add base to logical |
| and compare with |
| limit (MMU logic) |
+----------------------+
↓
Physical Address
Ensures that all memory accesses fall within the allocated range by comparing with base and
limit.
If RAM is full and a new process arrives, the OS swaps out an idle process to disk.
When the idle process becomes active again, it's swapped back in.
Swapping helps run more processes than physical memory can hold.
Compaction is the process of rearranging memory contents to bring all free spaces
together into one large block.
Efficient Memory Usage: Only required pages are loaded, saving memory.
For 5 marks :
1. Given memory partition of 150k, 500k, 200k, 300k and 550k (in order), how would each of
the first fit and best fit algorithm place the processes of 220k, 430k, 110k, 425k (in order).
Identify which algorithm makes the most efficient use of memory?
2. What is address translation? Consider a logical address space of 32 pages with 1024 words
per page (word = 8bits), mapped onto a physical memory of 16 frames.
a. How many bits are required in the logical address?
b. How many bits are required in the physical address?
I. Introduction (1 Mark)
Paging and Segmentation are two memory management schemes used to handle logical memory.
Paging divides memory into fixed-size blocks.
Segmentation divides memory into variable-size segments based on program structure.
Paging Example:
Segmentation Example:
I. Given: (1 Mark)
Start with empty frames, load pages as per order, replace the oldest page when full:
Step-wise:
[1] Fault → [1]
[2] Fault → [1,2]
[3] Fault → [1,2,3]
[5] Fault → Replace 1 → [5,2,3]
[2] Hit
[4] Fault → Replace 3 → [5,2,4]
[5] Hit
[6] Fault → Replace 2 → [5,6,4]
[2] Fault → Replace 4 → [5,6,2]
[1] Fault → Replace 5 → [1,6,2]
[2] Hit
[3] Fault → Replace 6 → [1,3,2]
[7] Fault → Replace 2 → [1,3,7]
[6] Fault → Replace 1 → [6,3,7]
[3] Hit
[2] Fault → Replace 7 → [6,3,2]
[1] Fault → Replace 6 → [1,3,2]
[2] Hit
[3] Hit
[6] Fault → Replace 1 → [6,3,2]
Maintain a stack of recently used pages, replace the least recently used:
1. Search a file
2. Create a file
3. Delete a file
4. Rename a file
6. Outline 2 advantages and 2 disadvantages of con guous file alloca on. (2 Marks)
Advantages:
Disadvantages:
For 5 marks :
1. Explain about file attributes and file operations.
I. File A ributes (2 Marks)
File a ributes store metadata about the file. Common ones include:
Directories organize files and maintain metadata like names, permissions, and structure.
1. Single-level Directory
o One directory for all files.
o Simple, but lacks user separa on.
2. Two-level Directory
o Separate directory per user.
o Avoids naming conflicts.
3. Tree-structured Directory
o Hierarchical folders (like Windows/Linux).
o Supports absolute and rela ve paths.
4. Acyclic Graph Directory
o Allows shared subdirectories/files via links.
Create/Delete
Search/Rename
Traverse Directory Tree