CS FundamentalsVery hardProduct company interview · GATE level
Use the same state: Allocation P0 (0,1,0,1), P1 (2,0,0,1), P2 (1,1,1,0), P3 (0,0,2,1), P4 (1,0,1,0); Max P0 (3,2,2,2), P1 (2,1,1,3), P2 (2,2,1,1), P3 (1,2,3,2), P4 (3,1,2,1); Available (1,1,1,1). Considered separately, can the banker's algorithm immediately grant (i) P4's request (1,0,0,0) and (ii) P1's request (0,0,1,0)?
- A. Neither can be granted
- B. Only P4's request can be granted
- C. Both can be granted
- D. Only P1's request can be granted
Correct answer: D. Only P1's request can be granted
Both requests are within the requester's need and within Available, so the safety test decides. (i) Granting P4 leaves Available (0,1,1,1). Every process then needs at least one A (P0 3, P2 1, P3 1, P4 1) except P1, which needs 2 of D - nobody can finish, so the state is unsafe and P4 must wait. (ii) Granting P1 leaves (1,1,0,1). P2 needs (1,1,0,1) and can finish, releasing to (2,2,1,1); then P3 or P4 can run, and so on to a complete safe sequence. A request that fits in Available is not automatically safe.
More Operating Systems questions
- A system with resource types A, B, C (several instances each) runs the deadlock-detection algorithm. Allocation: P0 (0,1,0), P1 (2,0,0)…
- Shared int x = 1. Thread T1 executes x = x + 1; twice; thread T2 executes x = x 2; once. Each statement compiles to a load of x into a…
- Semaphores a = 0 and b = 0. Three processes run concurrently: P: print('A'); signal(a); wait(b); print('B'); Q: wait(a); print('C')…
- Two processes (i = 0, 1; j = 1 - i) share bool flag[2] = {false, false} and int turn, and each runs entry code, then its critical section…
- How many lines print the value 3, and what is the sum of all the values printed? (Assume every fork() succeeds.) c int main() { int c = 0…
- A buddy allocator manages 1024 KB and splits blocks in powers of two, always using the lowest-addressed free block of the needed size…