CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

A Unix process opens a file, forks, and both parent and child each write 100 bytes to the inherited descriptor (no O_APPEND, no seeks), one after the other. What is the file size?

  1. A. 100 bytes, since each process writes at its own offset 0
  2. B. 200 bytes, since both share a single file offset
  3. C. Either 100 or 200 bytes, depending on order
  4. D. 200 bytes, but only when the file has O_APPEND set

Correct answer: B. 200 bytes, since both share a single file offset

fork duplicates descriptors that point to the SAME open-file description, which holds the offset. The first write advances it to 100, so the second write lands at 100: 200 bytes. Two separate open() calls would have separate offsets.

More Operating Systems questions

Exams that ask this topic