Exam Answers
Exam Answers
In contiguous allocation, each file occupies a set of consecutive blocks on the disk. This makes
accessing files very fast, as the system can retrieve the entire file in one go, especially during
sequential access. However, it can lead to external fragmentation where free space is scattered in
small blocks across the disk. An example is how early DOS file systems allocated files on a hard
drive.
Linked allocation links each file's blocks via pointers. Every block contains a pointer to the next block
in the sequence. This method eliminates external fragmentation but introduces overhead, as every
block must store a pointer, and it can be inefficient for random access. A real-world example would
Indexed allocation uses an index block to hold pointers to the actual blocks of a file. This makes
random access fast, as the entire index can be used to quickly locate blocks. However, this requires
additional space for the index. An example would be Unix file systems using inode structures for file
management.
---
2. Deadlock
a) Conditions for Deadlock (4 marks):
- Mutual Exclusion: A resource is non-shareable; only one process can use it at a time.
- Hold and Wait: A process holding a resource is waiting for another resource held by another
process.
- No Preemption: Resources cannot be forcibly removed from the process holding them.
- Circular Wait: A circular chain of processes exists, where each process is waiting for a resource
An example of this is two processes trying to access the same printer and a hard drive, each
To prevent deadlock, at least one of the conditions must be negated. For example:
- Hold and Wait: Require processes to request all their resources at once.
- Circular Wait: Impose a resource ordering rule, forcing processes to request resources in a
particular sequence.
An example is the Banker's Algorithm, which ensures safe resource allocation to avoid deadlocks.
---
Fragmentation is the inefficient use of memory, with internal fragmentation occurring when memory
allocated to a process is larger than required, and external fragmentation when free memory is
b) Multiple-Partition Allocation:
This is where memory is divided into fixed or variable-size partitions, and each partition is allocated
to one process at a time. The main problem with this method is fragmentation.
c) Contiguous Allocation:
Memory is allocated in a continuous block. It is simple to implement and offers fast access, but it
leads to external fragmentation. Memory compaction can be used to solve this problem.
d) Segmentation:
In segmentation, the process is divided into segments of different sizes according to its logical
structure, e.g., code, data, and stack segments. This method allows for easy access but suffers from
external fragmentation.
e) Paging:
Paging divides both physical memory and processes into fixed-size pages. It eliminates external
fragmentation but can introduce page table overhead. Pages are mapped to frames in physical
---
4. Differentiation (7 marks)
a) Demand Paging vs Pure Demand Paging (3 marks):
- Demand Paging: Pages are loaded into memory only when they are needed during execution.
- Pure Demand Paging: No pages are loaded until a page fault occurs. This is a more extreme form
of demand paging, where all processes start with zero pages in memory.
- Page Table: Maps virtual pages to physical frames in memory. It manages fixed-size pages.
- Segment Table: Maps segments of varying sizes to memory locations, used in segmentation.
- First-Fit Placement: Allocates the first available block that is large enough for the request.
- Best-Fit Placement: Searches for the smallest free block that fits the request to minimize wasted
space.