Professional Documents
Culture Documents
2240262_OS CIA III
2240262_OS CIA III
In deadlock avoidance, the request for any resource will be granted if the
resulting state of the system doesn't cause deadlock in the system. The state of
the system will continuously be checked for safe and unsafe states.
In order to avoid deadlocks, the process must tell OS, the maximum number of
resources a process can request to complete its execution.
The simplest and most useful approach states that the process should declare the
maximum number of resources of each type it may ever need. The Deadlock
avoidance algorithm examines the resource allocations so that there can never
be a circular wait condition.
To use the Banking algorithm to avoid deadlock, the system must keep
track of the available resources as well as the resources that are currently
assigned to each process. The system must also keep track of the
maximum number of resources that each process might require.
The Banking algorithm operates by defining a safety sequence, which is a
set of processes that can be completed without causing a deadlock. If a
system has at least one safety sequence, it is considered safe.
The Banking algorithm simulates the allocation and release of resources
for each process, beginning with the current allocation state, to determine
whether a system is safe. The system is considered safe if a sequence of
processes can be completed without entering a deadlock state.
Here is an example of how the Banking algorithm can be used to avoid
deadlock:
Suppose there are three processes (P1, P2, and P3) and three resources (R1, R2,
and R3). The maximum number of resources that each process may need is as
follows:
Process R1 R2 R3
P1 2 1 3
P2 1 3 2
Process R1 R2 R3
P3 1 2 1
Process R1 R2 R3
P1 2 0 1
P2 0 3 0
P3 1 0 1
To check whether this system is safe, the Banking algorithm simulates the
allocation and release of resources for each process. It starts with the current
allocation state and assumes that all processes will request their maximum
resources in turn.
The following are the Advantages and Disadvantages for the Banking
algorithm:
ADVANTAGES
1. It contains various resources that meet the requirements of each process.
2. Each process should provide information to the operating system for
upcoming resource requests, the number of resources, and how long the
resources will be held.
3. It helps the operating system manage and control process requests for
each type of resource in the computer system.
4. The algorithm has a Max resource attribute that represents indicates each
process can hold the maximum number of resources in a system.
DISADVANTAGES
Memory allocation is an essential part of any computer system, and there are
different techniques to allocate memory in a system. Two of the most common
techniques are contiguous and non-contiguous memory allocation. In this study,
we will discuss the working principles and differences between these two
techniques.
1. Contiguous Memory Allocation:
Contiguous memory allocation is basically a method in which a single
contiguous section/part of memory is allocated to a process or file needing it.
Because of this all the available memory space resides at the same place
together, which means that the freely/unused available memory partitions are
not distributed in a random fashion here and there across the whole memory
space.
The main memory is a combination of two main portions- one for the operating
system and other for the user program. We can implement/achieve contiguous
memory allocation by dividing the memory partitions into fixed size partitions.
Working Principle:
In the contiguous memory allocation technique, the operating system keeps
track of the available memory in the system. When a process requests memory,
the operating system searches for a contiguous block of memory of the required
size. If a block of memory of the required size is found, it is allocated to the
process, and the process can use it. If there is no contiguous block of memory of
the required size, the process has to wait until a sufficient amount of memory is
available.
Differences:
The contiguous memory allocation technique is simple and easy to implement.
It is also efficient in terms of memory access, as the entire block of memory
allocated to a process is contiguous, and there is no need to traverse different
memory locations to access data. However, one of the significant drawbacks of
this technique is fragmentation. As processes are created and terminated, the
memory gets fragmented, and it becomes challenging to find contiguous blocks
of memory for new processes.
Disadvantages
1. Fragmentation isn't a problem because every new file may be written to
the end of the disk after the previous one.
2. When generating a new file, it must know its eventual size to select the
appropriate hole size.
3. When the disk is filled up, it would be necessary to compress or reuse the
spare space in the holes.
4.
2. Non-Contiguous Memory Allocation :
Non-Contiguous memory allocation is basically a method on the contrary to
contiguous allocation method, allocates the memory space present in different
locations to the process as per it’s requirements. As all the available memory
space is in a distributed pattern so the freely available memory space is also
scattered here and there. This technique of memory allocation helps to reduce
the wastage of memory, which eventually gives rise to Internal and external
fragmentation.
Working Principle:
In the non-contiguous memory allocation technique, the operating system keeps
track of the available memory in the system. When a process requests memory,
the operating system searches for available memory blocks in the system and
allocates them to the process. These memory blocks can be located anywhere in
the memory, and they do not need to be contiguous.
Differences:
The non-contiguous memory allocation technique can efficiently use the
available memory in the system and can reduce fragmentation. However, it is
more complex than contiguous memory allocation, as the operating system
needs to keep track of multiple memory blocks allocated to a process. The non-
contiguous memory allocation technique can also have an impact on memory
access times, as the data may be scattered throughout the memory, and there
may be a need to traverse different memory locations to access the data.
Disadvantages
1. The downside of this memory allocation is that the access is slow because
you must reach the other nodes using pointers and traverse them.
Non-Contiguous Memory
S.NO. Contiguous Memory Allocation Allocation
Non-Contiguous memory
Contiguous memory allocation
allocation allocates separate
1. allocates consecutive blocks of
blocks of memory to a
memory to a file/process.
file/process.
Conclusion:
REFERENCES:
1. https://www.geeksforgeeks.org/difference-between-contiguous-and-
noncontiguous-memory-allocation/
2. https://www.javatpoint.com/contiguous-and-non-contiguous-memory-
allocation-in-operating-system
3. https://www.geeksforgeeks.org/bankers-algorithm-in-operating-system-
2/
4. https://www.javatpoint.com/bankers-algorithm-in-operating-system