0% found this document useful (0 votes)
11 views15 pages

QB Solutions

The document outlines the syllabus for the Operating System course at Don Bosco Institute of Technology, focusing on process coordination, memory management, and storage management. It includes a question bank covering key concepts such as deadlocks, synchronization problems, and memory allocation techniques, along with examples and explanations of algorithms like Banker's and LRU. The document serves as a comprehensive guide for students to understand operating system principles and prepare for assessments.

Uploaded by

tanvikhicchi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views15 pages

QB Solutions

The document outlines the syllabus for the Operating System course at Don Bosco Institute of Technology, focusing on process coordination, memory management, and storage management. It includes a question bank covering key concepts such as deadlocks, synchronization problems, and memory allocation techniques, along with examples and explanations of algorithms like Banker's and LRU. The document serves as a comprehensive guide for students to understand operating system principles and prepare for assessments.

Uploaded by

tanvikhicchi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

The Bombay Salesian Society’s

Don Bosco Institute of Technology, Mumbai -400070. Department of


Information Technology

SE ITC403:Operating System Even Sem AY: 2024-25

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.

The Producer-Consumer problem is a classical example of a multi-process synchronization


problem. It illustrates the difficulties of synchronizing access to shared memory (the buffer) when
multiple processes are involved.

 A producer generates data and stores it in a shared buffer.


 A consumer takes data from the buffer and processes it.
 The challenge is to ensure that:
o The producer doesn't add data into a full buffer.
o The consumer doesn't remove data from an empty buffer.

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.

 Nodes: Represent either Processes (P1, P2,...) or Resources (R1, R2,...).


 Edges:
o A request edge (P → R): Process requests a resource.
o An assignment edge (R → P): Resource is assigned to a process.

Deadlock Example with RAG:

 Process P1 holds R1 and requests R2.


 Process P2 holds R2 and requests R1. This forms a circular wait, indicating a deadlock.
3. What is deadlock and starvation?
4. Deadlock occurs when a group of processes are each waiting for another to release a
resource, and none can proceed.
5. Starvation is when a process waits indefinitely to acquire a resource because other
processes keep getting preference over it.

Deadlock causes complete halt, whereas starvation causes unfairness and delay.

6. Explain necessary and sufficient conditions for deadlock?

The four Coffman Conditions necessary for a deadlock are:

1. Mutual Exclusion: At least one resource is held in a non-shareable mode.


2. Hold and Wait: A process holding resources can request more.
3. No Preemption: A resource can only be released voluntarily.
4. Circular Wait: A closed chain of processes exists where each holds a resource the next
needs.

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.

 Used only for single-instance resources.


 Simplifies deadlock detection by checking for cycles in the graph.
 Unlike RAG, WFG shows direct process-to-process dependencies.

8. Explain data structures used in Bankers algorithms.

Banker’s algorithm uses the following data structures:

 Available: Vector indicating available instances of each resource.


 Max: Matrix indicating the max demand of each process.
 Allocation: Matrix showing current allocation.
 Need: Calculated as Max - Allocation.

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)

 Shared buffer with limited capacity.


 Producers add items, consumers remove items.
 Use semaphores:
o mutex for mutual exclusion.
o empty to count empty slots.
o full to count filled slots.

Key Challenge: Avoid race conditions, buffer overflows, and underflows.

Readers-Writers Problem

 Many processes either read or write shared data.


 Multiple readers allowed simultaneously.
 Only one writer allowed, and no readers or writers can access data during a write.

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.

Tools Used: Semaphores and reader-writer locks.

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:

 Use a semaphore for each chopstick.


 Use an arbitrator or change the order of acquiring chopsticks.
 Use a max of four philosophers attempting to eat simultaneously.

Demonstrates deadlock prevention, avoidance, and fair scheduling.

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

ii) Check for Safe State:

Work = Available = [3,3,2]


Finish = [False, False, False, False, False]

 P1 can finish → New Work = [5,3,2]


 P3 can finish → New Work = [7,4,3]
 P4 can finish → New Work = [7,4,5]
 P0 can finish → New Work = [7,5,5]
 P2 can finish → New Work = [10,5,7]

Safe State exists


[3 Marks]

iii) Safe Sequence:

P1 → P3 → P4 → P0 → P2

[1 Mark]

3. Explain Deadlock Prevention and Avoidance techniques.

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.

II. Deadlock Prevention (2 Marks)

Involves breaking Coffman’s four conditions:

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.

III. Deadlock Avoidance (2 Marks)

Requires the system to have advance knowledge of resource usage.

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

Advantages: More flexible than prevention.


Disadvantages: Requires prior resource information, computational overhead.

4. Explain Deadlock Detection technique with an example.

I. Introduction (1 Mark)

Detection is used when prevention/avoidance is not enforced. System periodically checks for
circular waits or deadlocks.

II. Single Instance Resource Model (1 Mark)


Use Wait-for Graph (WFG):

 Constructed from Resource Allocation Graph (RAG) by eliminating resources.


 A cycle in WFG implies deadlock.

III. Multiple Instance Resource Model (1 Mark)

Similar to Banker's Algorithm but works after resource allocation:

 Track:
o Available, Allocation, Request for each process.
 Algorithm tries to simulate process completion.
 If no process can proceed with current Available → deadlock.

IV. Example (1.5 Marks)

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

 Start with Work = Available


 Check which processes can complete with current Work
 If no further process can proceed → Deadlock Detected

V. Conclusion (0.5 Marks)

 Detection allows more flexible allocation.


 But requires:
o Extra overhead
o Post-deadlock recovery like killing processes or preemption
Module-4 Memory Management
For 2 marks :

1. Define logical address and physical address.

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

2. Explain logical address space and physical address space.

Logical Address Space: The range of addresses generated by a program (visible to the
user).

Physical Address Space: The range of addresses corresponding to physical memory


locations.

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.

(You can draw this during the exam)

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.

4. Explain swapping with an example.

Swapping is a technique of temporarily moving inactive processes from main memory to a


backing store (disk) to free space.
Example:

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

5. Explain compaction technique with an example.

Compaction is the process of rearranging memory contents to bring all free spaces
together into one large block.

Example: If memory has holes like:

[Process A][Free][Process B][Free][Process C]

Compaction reorders to:

[Process A][Process B][Process C][Big Free Block]

Used to reduce external fragmentation.

6. Outline advantages of demand paging.

 Efficient Memory Usage: Only required pages are loaded, saving memory.

 Faster Process Start: No need to load entire process; improves responsiveness.

 Multiprogramming Increases: More processes can reside in memory simultaneously.

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. Problem Given (1 Mark)

 Logical address space: 32 pages


 Each page = 1024 words
 Physical memory: 16 frames
 Word size = 8 bits (this is just info; not used for bit calculation)
We need to find:

a) Bits in logical address


b) Bits in physical address

II. Formulae Used (1 Mark)

 Logical Address = log2(Number of Pages) + log2(Page Size)


 Physical Address = log2(Number of Frames) + log2(Page Size)

III. Calculate Logical Address Bits (1.5 Marks)

 Pages = 32 ⇒ log2(32) = 5 bits


 Page Size = 1024 ⇒ log2(1024) = 10 bits

Total bits for Logical Address = 5 + 10 = 15 bits

So, logical addresses require 15 bits.

IV. Calculate Physical Address Bits (1.5 Marks)

 Frames = 16 ⇒ log2(16) = 4 bits


 Page Size = 1024 ⇒ log2(1024) = 10 bits

Total bits for Physical Address = 4 + 10 = 14 bits

So, physical addresses require 14 bits.

V. Final Answer (1 Mark)

 a) 15 bits are required for the logical address


 b) 14 bits are required for the physical address

This covers full marks with breakdown and clarity.

3. Compare and contrast paging and segmentation.

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.

II. Comparison Table (3 Marks)

Feature Paging Segmentation


Divides memory into logical
Memory Division Divides memory into fixed-size pages
segments
Size Pages are of equal size Segments are of variable size
Address Format Page number + Offset Segment number + Offset
Efficient use of memory, avoid Logical division based on
Purpose
fragmentation code/data/stack
Fragmentation May cause internal fragmentation May cause external fragmentation
Transparency to
Invisible to the user Visible and logical to the user
user
Table Used Page Table Segment Table

III. Example (1 Mark)

Paging Example:

 Process size = 4 KB, Page size = 1 KB → 4 pages created.


 Logical address: Page No (2 bits) + Offset (10 bits) = 12 bits total.

Segmentation Example:

 Code = 2 KB, Stack = 1 KB, Data = 1 KB → 3 segments created.


 Logical address = Segment No (2 bits) + Offset (depending on segment size)

IV. Conclusion (0.5 Marks)

 Paging is suited for memory efficiency and avoids external fragmentation.


 Segmentation aligns with programmer’s view but needs better management to avoid
fragmentation.

4. Consider the following page reference string 1,2,3,5,2,4,5,6,2,1,2,3,7,6,3,2,1,2,3,6. Calculate


the page faults by using a) LRU and b) FIFO algorithms for a memory with 3 frames.

I. Given: (1 Mark)

Page Reference String:


1, 2, 3, 5, 2, 4, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
Number of Frames: 3
We will calculate page faults using:

 FIFO (First-In First-Out)


 LRU (Least Recently Used)

II. FIFO Algorithm Simulation (2 Marks)

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]

Total Page Faults (FIFO) = 15

III. LRU Algorithm Simulation (2 Marks)

Maintain a stack of recently used pages, replace the least recently used:

[1] Fault → [1]


[2] Fault → [1,2]
[3] Fault → [1,2,3]
[5] Fault → Replace LRU(1) → [5,2,3]
[2] Hit → [2,5,3]
[4] Fault → Replace LRU(3) → [2,5,4]
[5] Hit → [5,2,4]
[6] Fault → Replace LRU(4) → [5,2,6]
[2] Hit → [2,5,6]
[1] Fault → Replace LRU(5) → [2,1,6]
[2] Hit → [2,1,6]
[3] Fault → Replace LRU(6) → [2,1,3]
[7] Fault → Replace LRU(1) → [2,3,7]
[6] Fault → Replace LRU(2) → [6,3,7]
[3] Hit
[2] Fault → Replace LRU(7) → [6,3,2]
[1] Fault → Replace LRU(6) → [1,3,2]
[2] Hit
[3] Hit
[6] Fault → Replace LRU(1) → [6,3,2]

Total Page Faults (LRU) = 12

IV. Conclusion (0.5 Marks)

 LRU (12 faults) performs better than FIFO (15 faults).


 LRU reduces page faults by tracking recent usage, though it’s more complex to implement.

Module-5 Storage Management


For 2 marks :
1. Explain any 4 file attributes.
2. Explain any 4 file operations.
3. Explain any 4 file types.
4. Name any 4 file allocation methods.
5. List any 4 directory operations.
6. Outline 2 advantages and 2 disadvantages of contiguous file allocation.
1. Explain any 4 file a ributes. (2 Marks)

1. Name – Iden fies the file.


2. Type – Determines the file's format (e.g., .txt, .exe).
3. Size – Indicates the file’s current length in bytes.
4. Loca on – Points to the physical address on disk.

2. Explain any 4 file opera ons. (2 Marks)

1. Create – Make a new file.


2. Write – Add data to a file.
3. Read – Retrieve data from a file.
4. Delete – Remove a file permanently.

3. Explain any 4 file types. (2 Marks)

1. Text Files – Contain readable characters.


2. Binary Files – Store data in machine-readable format.
3. Executable Files – Contain programs.
4. Source Code Files – Wri en in programming languages like .c, .java.

4. Name any 4 file alloca on methods. (2 Marks)

1. Con guous Alloca on


2. Linked Alloca on
3. Indexed Alloca on
4. Extent-based Alloca on (used in modern systems like NTFS)

5. List any 4 directory opera ons. (2 Marks)

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:

1. Fast sequen al and direct access.


2. Simple implementa on.

Disadvantages:

1. External fragmenta on.


2. File size must be known in advance.

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:

1. Name – Human-readable iden fier.


2. Type – Indicates format or usage (e.g., .doc, .exe).
3. Size – Length of the file in bytes.
4. Loca on – Disk address.
5. Protec on – Permissions (read/write/execute).
6. Time, date & user info – Helps in audi ng and access control.

II. File Opera ons (3 Marks)

File systems support several opera ons:

1. Create – Allocates space and assigns metadata.


2. Open/Close – Prepares file for access and releases it a er opera ons.
3. Read/Write – Transfer data to/from memory.
4. Delete – Removes directory entry and deallocates blocks.
5. Reposi on (Seek) – Moves read/write pointer to a desired loca on.

2. Explain different file access methods.


I. Sequen al Access (2 Marks)

 Data is accessed in a linear order.


 Used in compilers, media files.
 Opera ons: Read next, write next.

II. Direct (Random) Access (2 Marks)

 Access any block directly using address.


 Supports opera ons like seek(n) for quick lookups.
 Used in databases.

III. Indexed Access (1 Mark)

 Uses an index to access file blocks.


 Like a book index: fast and flexible.
 Used in large files and mul media.

3. Describe different allocation methods with reference to File Systems.

I. Con guous Alloca on (1.5 Marks)

 Stores file blocks in a single con guous chunk.


 Advantage: Fast access.
 Disadvantage: External fragmenta on, file size must be known.

II. Linked Alloca on (1.5 Marks)

 Each block points to the next.


 Advantage: No external fragmenta on.
 Disadvantage: No random access.

III. Indexed Alloca on (2 Marks)

 Maintains an index block with pointers to all file blocks.


 Advantage: Supports direct access.
 Disadvantage: Overhead for small files due to index.

4. Explain Directory structure.


I. Purpose (1 Mark)

Directories organize files and maintain metadata like names, permissions, and structure.

II. Types of Structures (3 Marks)

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.

III. Opera ons on Directories (1 Mark)

 Create/Delete
 Search/Rename
 Traverse Directory Tree

You might also like