Os Unit 02 Renew
Os Unit 02 Renew
Memory Each process has its own memory Threads share the same
space memory space of the process
Communication Inter-process communication Direct communication between
(IPC) needed threads (fast)
Overhead More overhead due to separate Less overhead, as threads share
memory space and resources resources
Execution Executes independently Executes concurrently with
other threads in the same
process
Threads are lighter-weight and more efficient for multitasking within the same process,
whereas processes are used when tasks require separate memory spaces or more
isolation.
Deadlock:
DEADLOCK Prevention: Deadlock Prevention aims to ensure that at least one of the necessary conditions for deadlock does not occur,
thus preventing deadlock from ever happening. Strategies for Deadlock Prevention: Eliminating Mutual Exclusion: Not always feasible
because some resources (e.g„ printers, disk drives) must be exclusive. However. it may be possible for some resources to be shared
among processes (e.g. readonly files). Eliminating Hold and Wait: A process must request all the resources it needs at once and must
not hold any resources while waiting for others. Eliminating No Preemption: Resources can be preempted from processes if they are
holding resources and waiting for others. If a process IS holding resources that other processes need. the system may take resources
from the process and give them to other processes. This approach could lead to higher system overhead and complex resource
management. Eliminating Circular Wait: This can be achieved by Imposing a stnctordenng of resource requests. Constance, resources
could be numbered and processes can only request resources in increasing order of their IDs, ensuring no cycles in resource request.
Deadlock:
Deadlock Avoidance: Deadlock Avoidance involves making dynamic decisions about resource allocation to ensure that deadlock will
never occur. It is more flexible than deadlock prevention because It allows processes to request resources as needed. but the system
ensures that such requests do not lead to deadlock. Strategies for Deadlock Avoidance: Banker's Algorithm: One of the most well-
known deadlock avoidance algorithms, used primarily in systems where resources are allocated dynamically. The systern must know in
advance the maximum resources each process will need When a process requests resources, the OS checks whether granting the
request would leave the system in a sate state (a state where deadlock is not possible). Safe State A state where there exists a sequence
of processes that con each be allocated the resources it needs and eventually terminate. Unsafe State: State Where no such sequence
exists, leading to potential deadlock The Bankers algorithm uses the following approach: Before granting a resource request. the system
checks if it is possible to allocate resources without leading to deadlock, by simulating resource allocation and checking whether the
system can eventually reach a safe State. Resource Allocation Graph (RAG) with Claim Edge: In the RAG. o •claim edge' is used to
represent a process that may eventually request a resource. If granting a request would result in a cycle in the graph, the request is
denied. This prevents circular wait conditions from forming.