Quiz Space

Operating Systems · Quiz 2 · 16 Mar 2025 · January 2025 term

Question 14: Consider the following code snippet from Bakery Algorith…

Question 14

+4 marksNumerical answer

Consider the following code snippet from Bakery Algorithm.

c
lock(i) {
num[i] = MAX(num[0], num[1], ..., num[N-1]) + 1;
for (p = 0; p < N; ++p) {
while (num[p] != 0 && num[p] < num[i]);
}
}

critical section

c
unlock(i) {
num[i] = 0;
}

Considering that there are 5 processes, and initially num[0]=3 num[1]=0, num[2]=5, num[3]=2, num[4]=4, If Process 4 (num[3]) starts executing its critical section and then unlocks, what will be the new value of num[3] after P4 finishes execution?

Show answer

Correct answer: 0

Question 14 of 17 in the IIT Madras BS Operating Systems (Operating Systems) Quiz 2 paper sat on 16 Mar 2025, in the January 2025 term (IIT M IMPROVEMENT AN EXAM QIM2 16 Mar 2025). It carries 4 marks.

This question was also asked in

More questions from this paper

  1. Q1Consider the following scenario where two processes are sharing a common variable. Global setup Process 1 Process 2 Whi…
  2. Q2Assume that two processes P1 and P2 are using a shared resource. If P1 and P2 are both waiting indefinitely to enter th…
  3. Q3Figure question
  4. Q4Identify the correct system call that should be used at LINE-1 to execute the grep command in the following code:
  5. Q5What is the correct sequence of tasks that takes place during hardware interrupt handling? (i) Save the current CPU sta…
  6. Q6Which of the following is a disadvantage of the Shortest Job First (SJF) scheduling algorithm?
  7. Q7State True or False: In inter-process communication (IPC) using shared memory, the commonly used system calls are send …
  8. Q8Given the hexadecimal view of the first few bytes of different files, identify the executable file (ELF file) from the …
  9. Q9Figure question
  10. Q10Which scheduling algorithm is optimal in terms of minimizing the average waiting time?
  11. Q11What is the main drawback of a priority-based scheduling algorithm?
  12. Q12Assume that context switches can occur at any time during the execution of the following code snippet. The variable cou…
  13. Q13Choose all the correct statements regarding compiling and linking multiple C source files using gcc.
  14. Q15Figure question
  15. Q16Figure question
  16. Q17Figure question