All Exams  >   Computer Science Engineering (CSE)  >   Operating System  >   All Questions

All questions of Concurrency & Deadlock for Computer Science Engineering (CSE) Exam

Busy Waiting in process synchronisation is a term used when a process is in critical section and other processes are waiting to enter critical section. Busy Waiting is also called ___________
  • a)
    Bounded Waiting
  • b)
    Busy processing
  • c)
    Spin Lock 
  • d)
    None of these
Correct answer is option 'C'. Can you explain this answer?

Sudhir Patel answered
Bounded Waiting: This is a condition that needs to be fulfilled to achieve synchronisation.
  • It says that no process has to wait forever to enter into a critical section.
  • There should be a specific time after which it should get a chance to enter into the critical section.
  • If bounded waiting is not fulfilled, it can suffer from starvation.
Busy processing: There is no such thing as busy processing.
Spin Lock: Also called Busy Waiting. 
  • ​When a process is in the critical section and other processes are waiting to enter the critical section then it is called spinlock.

Suppose we have a system in which processes is in hold and wait condition then which of the following approach prevent the deadlock.
  • a)
    Request all resources initially
  • b)
    Spool everything
  • c)
    Take resources away
  • d)
    Order resources numerically
Correct answer is option 'A'. Can you explain this answer?

Ruchi Sengupta answered
Preventing Deadlock by Requesting All Resources Initially

Deadlock is a situation in which two or more processes are unable to proceed because each is waiting for the other to release resources. It can occur in a system with limited resources and processes that are holding resources while waiting for other resources to be released.

One approach to prevent deadlock is to request all resources initially. This means that when a process needs to execute, it requests all the resources it will need for its entire execution before it starts. This approach can help prevent deadlock by ensuring that a process has all the necessary resources before it begins execution.

Advantages of Requesting All Resources Initially:
-Preventing Resource Deadlock: By requesting all resources initially, a process can ensure that it has all the resources it needs for its execution. This prevents the situation where a process holds some resources and waits for others, leading to deadlock.
-Efficient Resource Allocation: Requesting all resources initially allows the system to allocate resources more efficiently. Since a process requests all the resources it needs at once, the system can determine if there are enough resources available to satisfy the request. If there are not enough resources, the system can allocate them to other processes that can make progress, avoiding resource wastage.

Disadvantages of Requesting All Resources Initially:
-Resource Overallocation: Requesting all resources initially may lead to resource overallocation, where a process requests more resources than it actually needs. This can result in resource wastage and inefficient resource utilization.
-Low Concurrency: Requesting all resources initially can reduce the level of concurrency in the system. Since a process needs to wait until it acquires all the resources it needs, other processes may have to wait for a long time before they can execute, leading to decreased system performance.

Overall, requesting all resources initially can be an effective approach to prevent deadlock in a system. However, it is important to carefully consider the resource requirements of each process and balance the need for preventing deadlock with the need for efficient resource utilization and system performance.

Dijkstra’s banking algorithm in an operating system performs
  • a)
    Deadlock avoidance
  • b)
    Deadlock recovery
  • c)
    Mutual exclusion
  • d)
    Context switching
Correct answer is option 'A'. Can you explain this answer?

Banker’s algorithm resources will only be allocated if system will remain in SAFE state (DEADLOCK can’t occur if system is in SAFE state), so performing DEADLOCK AVOIDANCE.

Which of the following is NOT true of deadlock prevention and deadlock avoidance schemes?
  • a)
    In deadlock prevention, the request for resources is always granted if the resulting state is. safe.
  • b)
    In deadlock avoidance, the request for resources is always granted if the resulting state is safe.
  • c)
    Deadlock avoidance is less restrictive than deadlock prevention. 
  • d)
    Deadlock avoidance requires knowledge of resource requirements a priori.
Correct answer is option 'A'. Can you explain this answer?

Deadlock Prevention and Deadlock Avoidance

Deadlock prevention and deadlock avoidance are two different strategies used to handle the problem of deadlocks in a computer system.

Deadlock Prevention

In deadlock prevention, the system tries to prevent deadlocks from occurring by ensuring that the four necessary conditions for deadlock do not occur. These conditions are mutual exclusion, hold and wait, no preemption, and circular wait. If any of these conditions are violated, the request for resources is always granted if the resulting state is safe. Deadlock prevention is considered to be a more restrictive approach than deadlock avoidance.

Deadlock Avoidance

In deadlock avoidance, the system tries to avoid deadlocks by predicting and preventing the occurrence of a deadlock before it actually happens. This is done by using techniques such as resource allocation graphs or banker's algorithm. In this approach, the request for resources is always granted if the resulting state is safe. Deadlock avoidance is considered to be less restrictive than deadlock prevention.

The Answer

The statement that is not true of deadlock prevention and deadlock avoidance schemes is option A, which states that in deadlock prevention, the request for resources is always granted if the resulting state is safe. This statement is incorrect because in deadlock prevention, the request for resources is not always granted even if the resulting state is safe. Deadlock prevention may require the system to deny the request for resources in order to prevent the occurrence of a deadlock.

Implementation of ________ may waste CPU cycles.
  • a)
    Spinlock
  • b)
    Sleep and Wake
  • c)
    Both of the above
  • d)
    None of the above
Correct answer is option 'A'. Can you explain this answer?

Sudhir Patel answered
Spinlock: It is also called Busy Waiting. It is a process synchronization technique that makes the process (task) wait for a particular operation to complete or check for a condition to satisfy before proceeding with its execution.
  • Spinlock wastes CPU cycles. The processes are busy checking the instructions and waiting to enter the critical section is called busy waiting.
Sleep and Wake: It is a very simple concept where a process that wants to enter into the critical section but the critical section is busy then the process will go to sleep. It will be woken by the other process which is currently in the critical section so that the sleeping process can wake up and enter into the critical section. This process is done to prevent the wastage of CPU cycles.

The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0.
How many times will process P0 print ‘0’? 
  • a)
    At least twice
  • b)
    Exactly twice
  • c)
    Exactly thrice
  • d)
    Exactly once
Correct answer is option 'A'. Can you explain this answer?

Crack Gate answered
Concept:
Binary semaphore which can take only two values 0 and 1 and ensure mutual exclusion.
A process is entered into the critical section only when the value of semaphore(s) = 1
Otherwise, it will wait until semaphore(s) >0
The semaphores are initialized as S0=1, S1=0, S2=0.
Because S0 =1 then P0 enter into the critical section and other processes will wait until either S1=1 or S2 =1
The minimum number of times 0 printed:
  • S0 =1 then P0 enter into the critical section
  • print '0'
  • then release S1 and S2 means S1 =1 and s2 =1
  • now either P1 or P2 can enter into the critical section
  • if P1 enter into the critical section
  • release S0
  • then P2 enter into the critical section
  • release S0
  • P1 enter into the critical section
  • print '0'
The minimum number of time 0 printed is twice when executing in this order (p0 -> p1 -> p2 -> p0)
The Maximum number of times 0 printed:
  • S0 =1 then P0 enter into the critical section
  • print '0'
  • Then release S1 and S2 means S1 =1 and s2 =1
  • Now either P1 or P2 can enter into the critical section
  • If P1 enter into the critical section
  • Release S0 means S0 =1
  • S0 =1 then P0 enter into the critical section
  • print '0'
  • Then P2 enter into the critical section
  • Release S0 means S0 =1
  • S0 =1 then P0 enter into the critical section
  • print '0'
Maximum no. of time 0 printed is thrice when execute in this order (p0 -> p1 -> p0 -> p2 -> p0)
So, At least twice will process P0 print ‘0’

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y - X is __________.
    Correct answer is '80'. Can you explain this answer?

    Sudhir Patel answered
    Maximum value (Y):
    • Process P1 reads the initial value 100 during execution P1 will update the value of D to (100 + 20 = 120) and writes it to memory.
    • P2 and P3 read the value 120 from the memory.
    • P2 will get executed before P1 and write the value (120 - 50 = 70) to memory. Since P3 is holding D = 120 after its execution D will be equal to (120 + 10 = 130) ∴ Y = 130
    Minimum value (X):
    • P1, P2 and P3 read the value 100 from the memory
    • P1 will execute first, after its execution it will update (D = 100 + 20 = 120)
    • After P1, P3 will execute and it will update the value to (D = 100 + 10 = 110)
    • Finally, P2 will be execute and D will be equal to 100 - 50 = 50 ∴ X = 50
    • Y - X = 130 - 50 = 80

    Two atomic operations permissible on Semaphores are __________ and __________.
    • a)
      wait, stop
    • b)
      wait, hold
    • c)
      hold, signal
    • d)
      wait, signal
    Correct answer is option 'D'. Can you explain this answer?

    Sudhir Patel answered
    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.
    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)
    {
        S++;
    }

    Necessary conditions for deadlock are
    • a)
      Non-preemption and circular wait
    • b)
      Mutual exclusion and partial allocation
    • c)
      Both (a) and (b)
    • d)
      None of the above
    Correct answer is option 'C'. Can you explain this answer?

    Vaishnavi Kaur answered
    For deadlock four necessary condition are to be met
    (i) Mutual exclusion
    (ii) Non-preemption
    (iii) Circular wait
    (iv) Partial allocation [Bounded waiting]

    'm' processes share 'n' resources of the same type. The maximum need of each process does not exceed 'n' and the sum all their maximum needs is always less than m + n. In this set up deadlock
    • a)
      Has to occur
    • b)
      May occur
    • c)
      Can never occur
    • d)
      None of the these
    Correct answer is option 'C'. Can you explain this answer?

    Rajesh Malik answered
    Assume m = 5 and n = 10
    That means, 5 processes are sharing 10 resources and worst case will be if everyone is demanding equal number of cases.
    So, for deadlock to be there every process must be holding 2 resources and seeking 1 more resource. This will make total demand to 15, which is nothing but 10 + 5 (m + n).
    However, as given maximum demand is always less than (m + n), so we can say there will never be a deadlock.

    Consider a counting Semaphore variable 'S'. Following are the semaphore operations performed: 18P, 3V, 7V, 2P, 6V. What can be the largest initial value of S to keep one process in suspended list?
    • a)
      3
    • b)
      4
    • c)
      5
    • d)
      None of the these
    Correct answer is option 'A'. Can you explain this answer?

    Mahesh Pillai answered
    To determine the largest initial value of S that keeps one process in the suspended list, let's analyze the given semaphore operations step by step.

    Given semaphore operations:
    - 18P: This operation tries to decrement the semaphore value by 18. If the semaphore value is already less than 18, the process will be suspended. Otherwise, it will continue. Let's assume the initial value of S is x, then after this operation, the new value of S will be (x - 18).

    - 3V: This operation increments the semaphore value by 3. After this operation, the new value of S will be (x - 18 + 3) = (x - 15).

    - 7V: This operation increments the semaphore value by 7. After this operation, the new value of S will be (x - 15 + 7) = (x - 8).

    - 2P: This operation tries to decrement the semaphore value by 2. If the semaphore value is already less than 2, the process will be suspended. Otherwise, it will continue. After this operation, the new value of S will be (x - 8 - 2) = (x - 10).

    - 6V: This operation increments the semaphore value by 6. After this operation, the new value of S will be (x - 10 + 6) = (x - 4).

    Now, we need to find the largest initial value of S such that it keeps one process in the suspended list. This means that after all the operations, the semaphore value should be less than 0 to suspend a process.

    So, we need to find the value of x that satisfies the following inequality: (x - 4) < />

    Solving this inequality, we get x < />

    Therefore, the largest initial value of S that keeps one process in the suspended list is 3.

    Hence, the correct answer is option A.

    A system has 3 processes sharing 4 resources. If each process needs a maximum of 2 units then, deadlock
    • a)
      Can never occur
    • b)
      May occur
    • c)
      Has to occur
    • d)
      None of the above
    Correct answer is option 'A'. Can you explain this answer?

    Abhijeet Unni answered
    At least one process will be holding 2 resources in case of a simultaneous demand from, all the processes. That process will release the 2 resources, thereby avoiding any possible deadlock.

    Mutex can also be referred to as ___________
    • a)
      Counting Semaphore
    • b)
      Binary Semaphore
    • c)
      Monitor
    • d)
      None of the above
    Correct answer is option 'B'. Can you explain this answer?

    Sudhir Patel answered
    Semaphores: It is a non-negative integer value used by various processes mutually exclusive to achieve synchronization. A semaphore S can be accessed by only two operations which are atomic and mutually exclusive in nature - Wait (P) and Signal (V). There are two types of semaphores:
    • Counting Semaphore: In this, the value of the semaphore is from an unrestricted integer domain, that is, it can have an integer value as high as we want.
    • Binary Semaphore: In this, the value can range only between 0 and 1. 
    Monitor: It is a high-level construct implemented using a programming language that packages the data and procedures to modify the data. Only one processor is allowed in the monitor at a time.
    Mutex: It is a locking mechanism used to synchronize access to a resource. Only one task can acquire the mutex, hence, ownership is associated with mutex and only the owner can release the lock. This whole system can be implemented using a binary semaphore hence, it is referred to as a binary semaphore.

    Consider a system having 'm' resources of the same type. These resources are shared by 3 processes A, B, C, which have peak time demands of 3, 4, 6 respectively. The minimum value of ‘m’ that ensures that deadlock will never occur is
    • a)
      13
    • b)
      12
    • c)
      11
    • d)
      14
    Correct answer is option 'A'. Can you explain this answer?

    Anisha Chavan answered
    M for which the system is deadlock-free is 9.

    To determine the minimum value of m, we need to consider the worst-case scenario where all processes are requesting their peak time demands simultaneously.

    In this case, process A requires 3 resources, process B requires 4 resources, and process C requires 6 resources. Therefore, the total number of resources required in the system is 3 + 4 + 6 = 13.

    To avoid deadlock, the system should have enough resources to satisfy the maximum resource demand of any process. Therefore, the minimum value of m should be equal to or greater than 13.

    However, since all processes are requesting their peak time demands simultaneously, it is possible for the system to enter a deadlock state if the number of available resources is exactly equal to the total resource demand.

    Therefore, the minimum value of m for which the system is deadlock-free is m = 13 + 1 = 14.

    However, since all resources in the system are of the same type, it is not possible to allocate fractional resources. Therefore, the minimum value of m should be an integer.

    Therefore, the minimum value of m for which the system is deadlock-free is m = 14.


    An operating system contains 3 user processes each requiring 2 units of resource R. The minimum number of units of R such that no deadlock will ever occur is
    • a)
      3
    • b)
      4
    • c)
      5
    • d)
      6
    Correct answer is option 'B'. Can you explain this answer?

    Dishani Basu answered
    Dead lock occurs when each of the 3 user processes hold one resource and make simultaneous demand for another. If there are 4 resources one of the 3 user processes will get the fourth instance of the resource and release one or both of the resource it is currently holding after using.

    At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operation were completed on this semaphore. The resulting value of the semaphore is
    • a)
      42
    • b)
      2
    • c)
      7
    • d)
      12
    Correct answer is option 'B'. Can you explain this answer?

    Sudhir Patel answered
    Concepts:
    V(S): Signal operation will increment the semaphore variable, that is, S++.
    P(S): Wait operation will decrement the semaphore variable., that is, S--.
    Data:
    Initial counting semaphore = I = 7
    Wait operation = 20 P
    Signal operation = 15 V
    Final counting semaphore = F
    Formula:
    F = I + 15V + 20P
    Calculation:
    F = 7 + 15(+1) + 20(-1)
    ∴ F = 2
    the resulting value of the semaphore is 2

    What is a reusable resource? 
    • a)
      that can be used by one process at a time and is not depleted by that use 
    • b)
      none of the mentioned
    • c)
      that can be used by more than one process at a time 
    • d)
      that can be shared between various threads 
    Correct answer is option 'B'. Can you explain this answer?

    Sanya Agarwal answered
    Reusable resource: A resource, such as a CPU or tape transport, that is not rendered useless by being used. A magnetic disk or tape can be used often indefinitely and are to be regarded as reusable resources. Compare consumable resources.

    The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.
    The number of distinct values that B can possibly take after the execution is __________.
      Correct answer is '3'. Can you explain this answer?

      Sudhir Patel answered
      Initial value of B is 2 //value stored in main memory
      Value of B = 4
      First execute P2()
      P2 ( ) {
      D = 2 * B;   // 2 × 2 = 4
      B = D – 1; // B = 4 – 1 = 3
      }
      write the value of B = 3 to memory
      execute P1()
      P1 ( ) {
      C = B – 1; // C = 3 – 1 = 2
      B = 2 * C; // B = 2 × 2 = 4
      }
      write the value of B = 4 is memory.
      Distinct value of B is 4.
      Value of B =3
      First Execute P1()
      P1 ( ) {
      C = B – 1; // C = 2 – 1 = 1
      B = 2 * C; // B = 2 × 1 =2
      }
      write the value of B = 2 to memory
      then execute P2()
      P2 ( ) {
      D = 2 * B;   // 2 × 2 = 4
      B = D – 1; // B = 4 – 1 = 3
      }
      write the value of B = 3 to memory
      One of the distinct values of B is 3.
      Value of B = 2
      First execute P2()
      P2 ( ) {
      D = 2 * B;   // 2 × 2 = 4
      B = D – 1; // B = 4 – 1 = 3
      }
      //don’t write to memory
      execute P1()  // with initial value of B = 2
      P1 ( ) {
      C = B – 1; // C = 2 – 1 = 1
      B = 2 * C; // B = 2 × 1 = 2
      }
      write the value B = 3 by P2() in memory.
      overwrite the value written by P2() as B = 2 by P1() in memory.
      One of the distinct values of B is 2.
      Therefore, the distinct values of B are 2, 3 and 4.
      The number of distinct values that B can possibly take after the execution is 3.

      ​Which of the following is true?
      • a)
        Deadlock occurs in both the cases
      • b)
        Deadlock occurs in (i) but not in (ii)
      • c)
        Deadlock occurs in (ii) but not in (i)
      • d)
        None of the above
      Correct answer is option 'B'. Can you explain this answer?

      In (a) the processes P1, P2 and P3 are in deadlock state. P2 waiting on P3. Which is held by P3. P1 is waiting on ft, which is held by P2. While P3 in waiting on R2 which is held by P1 and P2
      In (b) we can observe that P4 can release instance o f R2, which can be allocated to either P1 or P3, breaking the cycle. Deadlock does not occur in (b).

      Referring to below system state diagram how many resources are available?

      1. One instance of resource R1.
      2. Two instance of resource R2.
      • a)
        Only 1
      • b)
        Only 2
      • c)
        Both 1 and 2
      • d)
        Neither 1 nor 2
      Correct answer is option 'B'. Can you explain this answer?

      From the given RAG we can observe that there are 2 instance of R2 and a single instance process P1 holding resource R1, and requesting for resource R2. Process P2 is requesting for resource R1 and Resource R2.
      Hence at the given time both the instances of resource R2 are available.

      Chapter doubts & questions for Concurrency & Deadlock - Operating System 2025 is part of Computer Science Engineering (CSE) exam preparation. The chapters have been prepared according to the Computer Science Engineering (CSE) exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

      Chapter doubts & questions of Concurrency & Deadlock - Operating System in English & Hindi are available as part of Computer Science Engineering (CSE) exam. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.

      Operating System

      10 videos|100 docs|33 tests

      Top Courses Computer Science Engineering (CSE)

      Signup to see your scores go up within 7 days!

      Study with 1000+ FREE Docs, Videos & Tests
      10M+ students study on EduRev