CS FundamentalsHardGATE CS (PYQ pattern)
Binary semaphore m is initialised to 1. P1: P(m); print A; V(m); print B. P2: P(m); print C; V(m); print D. P3: P(m); print E; V(m). All three start together and may interleave arbitrarily. How many distinct output strings can be produced?
- A. 24
- B. 30
- C. 36
- D. 60
Correct answer: B. 30
Only the program orders A<B, C<D (and the lock-serialised prints A, C, E, which can occur in any order) constrain the output. Counting all interleavings of the three programs with the lock enforced gives 30 distinct strings.
More Operating Systems questions
- Priority-based preemptive scheduling with L (low), M (medium), H (high). L arrives at t=0 and needs 10 units; at t=1 L locks a mutex and…
- A C program runs: int i; for(i=0;i<4;i++){ if(fork()==0 && i%2==0) break; } printf("X"); Every process, including the original, reaches…
- Banker's algorithm with 3 resource types. Available = (1,1,1). Allocation rows P0..P3: (1,0,1), (0,2,0), (2,1,0), (1,1,1); Maximum rows…
- A disk has cylinders 0-199. The head is at cylinder 50 moving towards higher numbers. Pending requests: 176, 79, 34, 60, 92, 11, 41, 114…
- A 1024 KB buddy system (minimum block 32 KB, lowest-address-first allocation) serves A=70 KB, B=35 KB, C=80 KB, D=60 KB in that order…
- A system uses the clock (second-chance) page replacement with 4 frames. Initially all frames are empty; a page has its reference bit set…