CS FundamentalsVery hardGATE CS (PYQ pattern)

Every fork() succeeds, wait() blocks until some child has terminated (it returns at once if the caller has no un-waited children), and printing is unbuffered. main(): fork() creating C1; fork() creating C2; wait(); print P. C1: print X; fork() creating G; wait(); print Z. G: print g. C2: print Y. How many different output strings are possible over all schedules?

  1. A. 13
  2. B. 11
  3. C. 9
  4. D. 16

Correct answer: B. 11

Enumerating every interleaving (with wait releasing P after either C1 or C2 ends, and Z only after g) gives 11 distinct strings; XYPgZ, XYgPZ, XYgZP, XgYPZ ... are examples.

More Operating Systems questions

Exams that ask this topic