CS FundamentalsModerateHCL · Tech Mahindra pattern
Two processes must run statements S1 (in P1) and S2 (in P2) such that S2 never executes before S1. Using one semaphore `sync`, which is correct?
- A. sync = 1; P1: wait(sync); S1; signal(sync); P2: S2;
- B. sync = 1; P1: S1; signal(sync); P2: wait(sync); S2;
- C. sync = 0; P1: wait(sync); S1; P2: S2; signal(sync);
- D. sync = 0; P1: S1; signal(sync); P2: wait(sync); S2;
Correct answer: D. sync = 0; P1: S1; signal(sync); P2: wait(sync); S2;
With sync = 0, P2's wait blocks until P1 has done S1 and signalled. Initialising sync to 1 lets P2 pass wait immediately, so S2 could run first.
More Operating Systems questions
- A system has 32-bit virtual addresses, 4 KB pages and 4-byte page-table entries, and every page table must fit exactly in one page. How…
- A Unix-style inode has 12 direct pointers, 1 single-indirect and 1 double-indirect pointer. The block size is 1 KB and a block pointer is…
- Memory holes, in order, are 150 KB, 450 KB, 250 KB, 350 KB and 500 KB. Requests arrive in order: 240 KB, 410 KB, 130 KB, 380 KB. Which…
- What does this program print? (Assume fork() succeeds; the order of the two lines may vary.) c int x = 5; int main() { if (fork() == 0)…
- A resource-allocation graph contains a cycle. Which conclusion is correct?
- Reference string (times 1 to 14): 3, 5, 3, 1, 4, 4, 2, 1, 1, 6, 6, 6, 2, 5. With working-set window Δ = 4 references, what is the working…