Unit-2 Operating System
## **SHORT QUESTIONS (5 Marks Each)**
### 1. **Contiguous Memory Allocation**
**Q:** What is contiguous memory allocation?
**A:** Contiguous memory allocation assigns a single continuous block of memory to a process. It’s
simple and fast but can lead to external fragmentation.
---
### 2. **Non-contiguous Memory Allocation**
**Q:** What is non-contiguous memory allocation?
**A:** It allows a process to be allocated memory in multiple non-adjacent blocks, using structures
like paging and segmentation to manage memory efficiently.
---
### 3. **Swapping**
**Q:** What is swapping in memory management?
**A:** Swapping moves processes between main memory and disk to free memory for other
processes, increasing CPU utilization.
---
### 4. **Fragmentation**
**Q:** Differentiate between internal and external fragmentation.
**A:** Internal fragmentation wastes space within allocated memory; external fragmentation
happens when free memory is scattered, preventing allocation despite enough total space.
---
### 5. **Paging**
**Q:** Explain the concept of paging.
**A:** Paging divides memory into fixed-size pages and frames. It avoids external fragmentation
and allows non-contiguous allocation.
---
### 6. **Segmentation**
**Q:** How is segmentation different from paging?
**A:** Segmentation divides memory into variable-sized segments based on logical divisions like code,
data, and stack, while paging uses fixed-size blocks.
---
### 7. **Virtual Memory Management**
**Q:** What is virtual memory?
**A:** Virtual memory gives an illusion of a large memory by using disk space, allowing execution
of large programs that don’t fit in physical RAM.
---
### 8. **Demand Paging**
**Q:** What is demand paging?
**A:** In demand paging, pages are loaded into memory only when required, reducing memory use
and improving efficiency.
---
### 9. **Page Replacement Algorithms**
**Q:** Name and explain FIFO page replacement.
**A:** FIFO replaces the oldest loaded page. It’s simple but may lead to poor performance (e.g.,
Belady’s anomaly).
---
### 10. **Deadlock Characterization**
**Q:** List and explain the four necessary conditions for a deadlock.
**A:**
* Mutual Exclusion
* Hold and Wait
* No Preemption
* Circular Wait
---
### 11. **Deadlock Prevention**
**Q:** How can deadlock be prevented?
**A:** By violating at least one necessary condition like allowing preemption, avoiding hold and wait,
or avoiding circular wait.
---
### 12. **Deadlock Avoidance (RAG)**
**Q:** What is a Resource Allocation Graph (RAG)?
**A:** RAG visually represents process-resource allocation to detect potential cycles that may cause
deadlock.
---
### 13. **Wait-for Graph**
**Q:** How does a Wait-for Graph help in deadlock avoidance?
**A:** It simplifies the RAG by removing resources and focusing only on process dependencies to
detect deadlocks more easily.
---
### 14. **Banker’s Algorithm**
**Q:** What is Banker’s algorithm?
**A:** Banker’s algorithm checks if a system is in a safe state before resource allocation,
preventing deadlock by simulating future resource requests.
---
### 15. **Deadlock Detection Algorithm**
**Q:** How does the deadlock detection algorithm work?
**A:** It uses a matrix-based method to find unfulfilled resource requests and detects cycles that
indicate deadlocks.
---
## **LONG QUESTIONS (10 Marks Each)**
### 1. **Compare Contiguous and Non-contiguous Memory Allocation**
**Q:** Compare contiguous and non-contiguous memory allocation. Discuss advantages and
disadvantages.
**A:**
* Contiguous memory requires each process to be in one continuous block, making it simple and fast
for access, but causes external fragmentation and limits flexibility.
* Non-contiguous memory allows scattered allocation using paging/segmentation, improving
utilization and enabling virtual memory. However, it increases overhead due to address translation
and may cause internal fragmentation (in paging).
---
### 2. **Explain Paging and Page Replacement Algorithms**
**Q:** Describe paging and explain three page replacement algorithms with examples.
**A:**
* Paging divides memory into fixed-size pages/frames. Logical to physical address translation uses
page tables.
* **FIFO:** Replaces oldest page. Simple but inefficient.
* **LRU (Least Recently Used):** Replaces page not used recently. Better performance, but requires
tracking usage.
* **Optimal:** Replaces page not needed for longest time. Theoretical benchmark, not practical.
Example: Page sequence \[1,2,3,4,1,2,5] with 3 frames.
---
### 3. **Discuss Virtual Memory, Demand Paging, and its Benefits**
**Q:** What is virtual memory? Explain demand paging with advantages and disadvantages.
**A:**
* Virtual memory allows programs to use more memory than physically available by using disk
storage.
* Demand paging loads pages on access, reducing memory usage.
**Advantages:** Better memory use, allows large programs, cost-effective.
**Disadvantages:** Page faults may slow down execution; disk access is slower than RAM.
---
### 4. **Explain Deadlock Characterization and Prevention Methods**
**Q:** What are the conditions for deadlock? Describe prevention techniques for each.
**A:**
Deadlock requires:
1. **Mutual Exclusion** – Avoid by sharing resources.
2. **Hold and Wait** – Prevent by requesting all resources at once.
3. **No Preemption** – Allow preemption of resources.
4. **Circular Wait** – Impose resource ordering.
Breaking any one of these can prevent deadlock but may reduce system efficiency.
---
### 5. **Explain Banker’s Algorithm with Example**
**Q:** Explain the Banker’s algorithm for deadlock avoidance with a suitable example.
**A:**
Banker’s algorithm uses `Available`, `Max`, `Allocation`, and `Need` matrices. It checks if granting a
request leads to a safe state.
**Example:**
Processes: P0, P1
Resources: A=10
Allocation: P0=3, P1=2
Max: P0=7, P1=5
Available: 5
Safe sequence is checked using Need = Max - Allocation and work simulation.
---
Would you like this exported as a PDF or formatted for printing?
Here's a structured set of **5-mark short questions** and **10-mark long questions** covering
the topics you've listed in memory management and deadlock handling. Each question is paired with
a concise yet informative answer appropriate for exam-level preparation.
---
## **5 MARK QUESTIONS (Short Answer Questions)**
### 1. **Contiguous vs. Non-contiguous Memory Allocation**
**Q:** What is the difference between contiguous and non-contiguous memory allocation?
**A:**
* **Contiguous Allocation** assigns a single continuous block of memory to a process. It's simple
and fast but leads to external fragmentation.
* **Non-contiguous Allocation** allows a process to occupy multiple memory blocks scattered
throughout physical memory, reducing fragmentation and increasing flexibility.
---
### 2. **Swapping in Memory Management**
**Q:** What is swapping and why is it used in memory management?
**A:**
Swapping is the process of moving processes between main memory and disk to manage memory
efficiently. It helps in executing more processes than the available physical memory, allowing for
multiprogramming.
---
### 3. **Fragmentation**
**Q:** What is fragmentation? Differentiate internal and external fragmentation.
**A:**
* **Internal Fragmentation** occurs when allocated memory exceeds the process requirement.
* **External Fragmentation** happens when enough total memory exists but is not contiguous.
Fragmentation reduces memory utilization.
---
### 4. **Paging**
**Q:** How does paging eliminate external fragmentation?
**A:**
Paging divides memory into fixed-size blocks called pages and frames. Pages are mapped to frames
non-contiguously, allowing efficient memory use without needing contiguous allocation, thus
eliminating external fragmentation.
---
### 5. **Segmentation**
**Q:** What is segmentation in memory management?
**A:**
Segmentation divides memory into variable-sized logical units called segments (e.g., code, data,
stack). Each segment has its own base and limit, reflecting the logical structure of programs.
---
### 6. **Virtual Memory and Demand Paging**
**Q:** What is demand paging in virtual memory?
**A:**
Demand paging loads a page into memory only when it is needed. If the page is not in memory, a
**page fault** occurs, and the OS loads it from disk, allowing efficient memory usage and
execution of larger programs.
---
### 7. **Page Replacement Algorithms**
**Q:** Name and explain any two page replacement algorithms.
**A:**
* **FIFO (First In First Out):** Removes the oldest page in memory.
* **LRU (Least Recently Used):** Removes the page that hasn’t been used for the longest time.
---
### 8. **Deadlock Conditions**
**Q:** What are the necessary conditions for a deadlock to occur?
**A:**
1. **Mutual Exclusion**
2. **Hold and Wait**
3. **No Preemption**
4. **Circular Wait**
All four conditions must hold simultaneously for a deadlock.
---
### 9. **RAG and Wait-for Graph**
**Q:** How is a Wait-for Graph used to detect deadlocks?
**A:**
A Wait-for Graph represents processes and resources. A **cycle** in the graph indicates a deadlock.
It simplifies detection by focusing only on the processes waiting on each other, not all resources.
---
### 10. **Banker's Algorithm**
**Q:** What is the purpose of the Banker's algorithm?
**A:**
The Banker's algorithm prevents deadlock by allocating resources only if the system remains in a
**safe state**. It checks for a safe sequence before granting resources.
---
## **10 MARK QUESTIONS (Long Answer Questions)**
### 1. **Memory Management Techniques**
**Q:** Compare and contrast paging, segmentation, and virtual memory.
**A:**
* **Paging** divides memory into fixed-size pages and eliminates external fragmentation.
* **Segmentation** divides memory based on logical program structure (e.g., functions, arrays).
* **Virtual Memory** uses disk as an extension of RAM to execute large processes via paging and
swapping.
Virtual memory combines the benefits of paging and segmentation for efficient and flexible
memory management.
---
### 2. **Page Replacement Strategies**
**Q:** Explain page replacement algorithms with examples. Discuss which algorithm is best and why.
**A:**
* **FIFO** replaces the oldest page. Example: Page queue = \[1, 2, 3], incoming = 4 → Replace 1.
* **LRU** replaces the least recently used page.
* **Optimal** replaces the page that will not be used for the longest future time.
**Best:** Optimal gives the least page faults but is not practical. LRU performs well in most real
scenarios.
---
### 3. **Deadlock Characterization and Prevention**
**Q:** Explain the four conditions of deadlock with examples. How can deadlock be prevented?
**A:**
* **Mutual Exclusion:** Resources are non-shareable.
* **Hold and Wait:** A process holds one resource and waits for another.
* **No Preemption:** Resources cannot be forcibly taken.
* **Circular Wait:** Circular chain of processes exists.
**Prevention:** Break at least one condition, e.g., avoid circular wait by ordering resources or
preempting.
---
### 4. **Deadlock Avoidance and Banker's Algorithm**
**Q:** Describe the Banker's algorithm with a suitable example.
**A:**
Banker's algorithm checks if the system is in a **safe state** before allocating resources.
* For each process, check if needs can be satisfied with available + allocated.
* If yes, simulate allocation and continue; if not, deny request.
Example: With processes and resource matrices, simulate allocation and find a **safe sequence**
to avoid deadlock.
---
### 5. **Detection and Recovery from Deadlock**
**Q:** How can a system detect and recover from deadlock? Explain the detection algorithm.
**A:**
* **Detection:** Use a resource allocation matrix and available vector to check for cycles or
unfinishable processes.
* **Recovery:** Abort processes one by one or preempt resources.
Trade-offs include potential data loss or rollback overhead.
---
Would you like this content as a downloadable PDF or editable document?