What Are Necessary Conditions Which Can Lead To A Deadlock Situation in A System?
What Are Necessary Conditions Which Can Lead To A Deadlock Situation in A System?
Visibility The user can view the The user can never view
program. program
BASIS FOR
LOGICAL ADDRESS PHYSICAL ADDRESS
COMPARISON
Access The user uses the The user can not directly
address.
Internal Fragmentation
External Fragmentation
Internal Fragmentation
In this fragmentation, the process is allocated a memory block of size more than the
size of that process. Due to this some part of the memory is left unused and this
cause internal fragmentation.
Example: Suppose there is fixed partitioning (i.e. the memory blocks are of fixed
sizes) is used for memory allocation in RAM. These sizes are 2MB, 4MB, 4MB,
8MB. Some part of this RAM is occupied by the Operating System (OS).
Now, suppose a process P1 of size 3MB comes and it gets memory block of size
4MB. So, the 1MB that is free in this block is wasted and this space can’t be utilized
for allocating memory to some other process. This is called internal
fragmentation.
How to remove internal fragmentation?
This problem is occurring because we have fixed the sizes of the memory blocks. This
problem can be removed if we use dynamic partitioning for allocating space to the process.
In dynamic partitioning, the process is allocated only that much amount of space which is
required by the process. So, there is no internal fragmentation.
External Fragmentation
In this fragmentation, although we have total space available that is needed by a
process still we are not able to put that process in the memory because that space is
not contiguous. This is called external fragmentation.
Example: Suppose in the above example, if three new processes P2, P3, and P4
come of sizes 2MB, 3MB, and 6MB respectively. Now, these processes get memory
blocks of size 2MB, 4MB and 8MB respectively allocated.
So, now if we closely analyze this situation then process P3 (unused 1MB)and
P4(unused 2MB) are again causing internal fragmentation. So, a total of 4MB (1MB
(due to process P1) + 1MB (due to process P3) + 2MB (due to process P4)) is
unused due to internal fragmentation.
Now, suppose a new process of 4 MB comes. Though we have a total space of
4MB still we can’t allocate this memory to the process. This is called external
fragmentation.
Another way to remove external fragmentation is compaction. When dynamic partitioning is used
for memory allocation then external fragmentation can be reduced by merging all the free
memory together in one large block. This technique is also called defragmentation. This larger
block of memory is then used for allocating space according to the needs of the new processes.
Context
operating system simply switches either allowed time expires or where there
to, and executes, another job other reason for current process needs to
3. when current job needs to wait. wait (example process needs to do IO).
Multi-programming increases
The disadvantage of context switching is that it requires some time for context switching
i.e. the context switching time. Time is required to save the context of one process that is in
the running state and then getting the context of another process that is about to come in
the running state. During that time, there is no useful work done by the CPU from the user
perspective. So, context switching is pure overhead in this condition.
In the above diagram, the entry section handles the entry into the critical section. It acquires the resources
needed for execution by the process. The exit section handles the exit from the critical section. It releases
the resources and also informs the other processes that the critical section is free.
10.What is dispatcher?
A dispatcher is a special program which comes into play after the scheduler. When the scheduler
completes its job of selecting a process, it is the dispatcher which takes that process to the desired
state/queue. The dispatcher is the module that gives a process control over the CPU after it has been
selected by the short-term scheduler. This function involves the following:
Switching context
Switching to user mode
Jumping to the proper location in the user program to restart that program
11. What is Turn arround , waiting , response
time ?
Burst time is the total time taken by the process for its execution on the CPU.
Arrival time is the time when a process enters into the ready state and is ready for its
execution.
Waiting time is the total time spent by the process in the ready state waiting for
CPU.
Waiting time = Turnaround time - Burst time
Response time is the time spent when the process is in the ready state and gets the
CPU for the first time.
Response time = Time at which the process gets the CPU for the first
time - Arrival time
Turnaround time is the total amount of time spent by the process from
coming in the ready state for the first time to its completion.
or
Data Storage Page table stores the page data. Segmentation table stores the
8
segmentation data.
All the processes that are involved in the deadlock are terminated. This approach is not that useful
as all the progress made by the processes is destroyed.
Resources can be preempted from some processes and given to others until the deadlock
situation is resolved.
Deadlock Prevention
It is important to prevent a deadlock before it can occur. So, the system checks each transaction before it is
executed to make sure it does not lead to deadlock. If there is even a slight possibility that a transaction
may lead to deadlock, it is never allowed to execute.
Some deadlock prevention schemes that use timestamps in order to make sure that a deadlock does not
occur are given as follows −
The wait for graph shows the relationship between the resources and transactions. If a transaction requests
a resource or if it already holds a resource, it is visible as an edge on the wait for graph. If the wait for
graph contains a cycle, then there may be a deadlock in the system, otherwise not.
Ostrich Algorithm
The ostrich algorithm means that the deadlock is simply ignored and it is assumed that it will never occur.
This is done because in some systems the cost of handling the deadlock is much higher than simply
ignoring it as it occurs very rarely. So, it is simply assumed that the deadlock will never occur and the
system is rebooted if it occurs by any chance.