Core OS Concepts: Deadlocks, Memory, and Disk Storage
1. Four Necessary Conditions for Deadlock
Definition: Deadlock is a situation in which two or more processes wait indefinitely for resources held by each other.
The four necessary conditions for deadlock are:
- Mutual Exclusion: A resource can be used by only one process at a time.
Example: Only one process can use a printer at a time. - Hold and Wait: A process holds one resource and waits for another resource.
Example: A process holds a printer and waits for a scanner. - No Preemption: A resource cannot be forcibly taken away from a process. It must be released voluntarily.
Example: The OS cannot forcibly take a resource from a process in this condition. - Circular Wait: A circular chain of processes exists in which each process waits for a resource held by the next process.
2. Non-Contiguous Memory Management Techniques
Definition: Non-contiguous memory management is a technique in which a process is stored in different locations in main memory instead of one continuous block.
There are two main techniques:
1. Paging
Paging divides a process into fixed-size blocks called pages and physical memory into equal-sized blocks called frames. Pages can be stored in any available frames in physical memory.
Advantages:
- Eliminates external fragmentation.
- Allows efficient memory utilization.
2. Segmentation
Segmentation divides a program into variable-sized logical parts called segments, such as code, data, and stack. Each segment can be stored at a different location in physical memory.
Advantages:
- Divides programs into logical units.
- Supports protection and sharing of segments.
Conclusion: Paging divides memory into fixed-size blocks, whereas segmentation divides a program into variable-sized logical units.
3. Deadlock Prevention vs. Deadlock Avoidance
| # | Deadlock Prevention | Deadlock Avoidance |
|---|---|---|
| 1 | Prevents deadlock by eliminating at least one necessary condition. | Avoids deadlock by checking resource allocation requests. |
| 2 | Restricts how resources can be allocated. | Allocates resources only if the system remains in a safe state. |
| 3 | Does not require checking for a safe sequence for every allocation. | Requires checking whether a safe sequence exists. |
| 4 | May reduce resource utilization. | Can improve resource utilization compared with strict prevention. |
| 5 | Does not generally require knowing maximum resource needs in advance. | Usually requires advance knowledge of maximum resource requirements. |
| 6 | Example: Eliminating the hold-and-wait condition or circular wait. | Example: Banker's Algorithm. |
4. Bitmap Free-Space Management Technique
Definition: Bitmap is a free-space management technique used by the operating system to keep track of free and allocated disk blocks. Each disk block is represented by one bit.
- 0 represents a free block.
- 1 represents an allocated block.
English with a size of 3.61 KB