Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Process Management: Deadlock and Synchronization in Operating Systems, Study notes of Operating Systems

An overview of process management within operating systems, focusing on deadlocks, their characterization, and various handling approaches. It covers necessary and sufficient conditions for deadlocks, including prevention, avoidance, detection, and recovery methods. The document also discusses concurrent and dependent processes, critical sections, semaphores, and inter-process communication methods. Classical process synchronization problems like the producer-consumer and reader-writer problems are explained, offering a comprehensive understanding of process synchronization and resource management in operating systems. It further explores process synchronization, concurrent processes, and the critical section problem, detailing requirements such as mutual exclusion, progress, and bounded waiting. Semaphores and inter-process communication methods, including pipes and shared memory, are also discussed, providing a thorough overview of process management concepts.

Typology: Study notes

2024/2025

Available from 05/19/2025

raziya-shiak
raziya-shiak 🇮🇳

5 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OPERATING SYSTEM-3
Process Management: Deadlock,
Deadlock Characterization, Necessary and Sufficient
Conditions for Deadlock, Deadlock Handling
Approaches: Deadlock Prevention, Deadlock Avoidance
and Deadlock Detection and Recovery. Concurrent and
Dependent Processes, Critical Section, Semaphores,
Methods for Inter- process Communication; Process
Synchronization, Classical Process Synchronization
Problems: Producer-Consumer, Reader-Writer.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Process Management: Deadlock and Synchronization in Operating Systems and more Study notes Operating Systems in PDF only on Docsity!

OPERATING SYSTEM- 3

Process Management: Deadlock,

Deadlock Characterization, Necessary and Sufficient

Conditions for Deadlock, Deadlock Handling

Approaches: Deadlock Prevention, Deadlock Avoidance

and Deadlock Detection and Recovery. Concurrent and

Dependent Processes, Critical Section, Semaphores,

Methods for Inter- process Communication; Process

Synchronization, Classical Process Synchronization

Problems: Producer-Consumer, Reader-Writer.

PROCESS MANAGEMENT

1. What is Deadlock? Explain Deadlock Characterization? A process in operating system uses resources in the following way.

  1. Requests a resource
  2. Use the resource
  3. Releases the resource A deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. For example, in the below diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by process 2, and process 2 is waiting for resource 1. Necessary conditions for Deadlocks (Deadlock Characterization)
  4. Mutual Exclusion A resource can only be shared in mutually exclusive manner. It implies, if two processes cannot use the same resource at the same time. In the diagram below, there is a single instance of Resource 1 and it is held by Process 1 only.

2. Explain methods/Approaches for Handling Deadlocks? A deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. For example, in the below diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by process 2, and process 2 is waiting for resource 1. Methods for handling deadlock:

  1. Deadlock Prevention
  1. Deadlock Avoidance
  2. Deadlock Detection and Recovery
  3. Deadlock Ignorance 1. Deadlock Prevention let us take an example of a chair, as we know that chair always stands on its four legs. Likewise, for the deadlock problem, all the above given four conditions are needed. If anyone leg of the chair gets broken, then definitely it will fall. The same is the situation with the deadlock if we become able to violate any condition among the four and do not let them occur together then there can be prevented from the deadlock problem. 1. Mutual Exclusion A resource can only be shared in mutually exclusive manner. 2. Hold and Wait A process waits for some resources while holding another resource at the same time. 3.No preemption : The resource can be released by a process voluntarily i.e. after execution of the process. 4.Circular Wait All the processes must be waiting for the resources in a cyclic manner 2. Deadlock Avoidance When a process requests a resource, the deadlock avoidance algorithm examines the resource-allocation state. If allocating that resource sends the system into an unsafe state, the request is got granted. Therefore, it requires additional information such as how many resources of each type is required by a process. If the system enters into an unsafe state, it has to take a step back to avoid deadlock. 3. Deadlock Detection and Recovery We let the system fall into a deadlock and if it happens, we detect it using a detection algorithm and try to recover.

Advantages of concurrency

  1. Improved performance − Concurrency allows multiple tasks to be executed simultaneously, improving the overall performance of the system.
  2. Resource utilization − Concurrency allows better utilization of system resources, such as CPU, memory, and I/O devices.
  3. Responsiveness − Concurrency can improve system responsiveness by allowing multiple tasks to be executed concurrently
  4. Fault tolerance − Concurrency can improve the fault tolerance of the system by allowing tasks to be executed independently. If one task fails, it does not affect the execution of other tasks. 4. Explain Critical Section? Critical Section is a segment of code that can be accessed by only one process at a time. It contains shared resources that need to be accessed by all processes. If one process is executing in Critical Section, then, other Since only one process can access critical section, all other process must be stopped from accessing it. There should be some requirements that must be fulfilled while accessing it. process has to wait until the first one finishes

Critical Section problem must satisfy three requirements –

  1. Mutual Exclusion: If process Pi is executing in its Critical Section, then, no other process can be executing in their Critical Sections.
  2. Progress: If no process is executing in its Critical Section and there exist some process that wish to enter their Critical Section, then the selection of the processes that will enter the Critical Section can’t be postponed indefinitely.
  3. Bounded Waiting: After a process makes a request for getting into its Critical Section, there is a limit for how many other processes can get into their Critical Section, before this process’s request is granted. So, after the limit is reached, system must grant the process permission to get into its Critical Section. 5. Explain Semaphores in Operating System? Semaphores are integer variables that are used to solve the critical section problem by using two atomic operations, wait and signal that are used for process synchronization. The definitions of wait and signal are as follows −
  • Wait The wait operation decrements the value of its argument S, if it is positive. If S is negative or zero, then no operation is performed. wait(S) { while (S<= 0 ); S--; }
  • Signal The signal operation increments the value of its argument S. signal(S) {

6. Write about Methods for Inter- process Communication? Inter-process communication: A mechanism which is used to provide communications among several processes is known as inter-process communication or IPC and it is provided by the OS or operating system. This type of communication is very helpful in data exchanging among several threads in single or multiple programs or processes which run on single or several computers connected through a network. There are different modes of inter-process communication like pipes, socket, file, signal, shared memory message queue & message passing. The working of IPC mainly depends on a few important methods or approaches which are discussed below. 1. Pipes A Pipe is one type of data channel, extensively used for communication in between two processes is unidirectional. 2. Socket This is the endpoint to transmit or receive data within a network. This is true for data transmitted between processes on a similar computer otherwise between various computers on a similar network. Sockets are used by most of the operating systems for IPC or interprocess communication.

3. File A file is a data record that is stored on a disk on demand through a file server. Several processes can access a file as necessary. All operating systems utilize files for storing data. 4. Signal The signal is very useful in IPC in a restricted way. They are system messages transmitted from one process to another. 5. Message Queues A linked list of messages is known as a message queue that is stored in the kernel. It can be simply recognized through a message queue identifier. So this technique provides communication in between single. Message Queue

  1. Shared Memory Multiple processes can access a common shared memory. Multiple processes communicate by shared memory, where one process makes changes at a time and then others view the change. Shared memory does not use kernel.

In the above example, there are three processes, Process 1 is trying to write the shared data while Process 2 and Process 3 are trying to read the same data so there are huge changes in Process 2, and Process 3 might get the wrong data. Let’s understand some different sections of a program.

  • Entry Section:- This section is used to decide the entry of the process
  • Critical Section:- This section is used to make sure that only one process access and modifies the shared data or resources.
  • Exit Section:- This section is used to allow a process that is waiting in the entry section and make sure that finished processes are also removed from the critical section.
  • Remainder Section:- The remainder section contains other parts of the code which are not in the Critical or Exit sections. 8. Explain Classical Process Synchronization Problem? Semaphore can be used in other synchronization problems besides Mutual Exclusion. We will discuss the following problems: 1. Bounded Buffer (Producer-Consumer) Problem 2. The Readers Writers Problem 3. The Dining Philosophers Problem 1. The Bounded Buffer Problem (Producer Consumer Problem): Consider,
    • a buffer which can store n items
    • a producer process which creates the items (1 at a time)
    • a consumer process which processes them (1 at a time) A producer cannot produce unless there is an empty buffer slot to fill. A consumer cannot consume unless there is at least one produced item.

Semaphore empty=N, full=0, mutex=1; process producer { while (true) { empty.acquire( ); mutex.acquire( ); // produce mutex.release( ); full.release( ); } } process consumer { while (true) { full.acquire( ); mutex.acquire( ); // consume mutex.release( ); empty.release( ); } } The semaphore mutex provides mutual exclusion for access to the buffer

// protecting readerCount mutex.acquire( ); --readerCount; if (readerCount == 0) db.release; mutex.release( ); } readerCount is a over which we must maintain control and we use mutex to do so.

3. The Dining Philosophers Problem n philosophers sit around a table thinking and eating. When a philosopher thinks she does not interact with her colleagues. Periodically, a philosopher gets hungry and tries to pick up the chopstick on his left and on his right. A philosopher may only pick up one chopstick at a time and, obviously, cannot pick up a chopstick already in the hand of neighbor philosopher. The dining philosophers problems is an example of a large class or concurrency control problems; it is a simple representation of the need to allocate several resources among several processes in a deadlock-free and starvation-free manner.