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?
- A. 100 bytes, since each process writes at its own offset 0
- B. 200 bytes, since both share a single file offset
- C. Either 100 or 200 bytes, depending on order
- 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
- Which statement about the convoy effect is correct?
- Disk cylinders 0–199; the head is at 120 moving toward 199; requests: 10, 22, 20, 2, 40, 6, 38. Counting the return jump as head movement…
- Which property of a journaling file system's ordered mode is correct?
- A process's address space uses three-level paging with 9 bits per level and 4 KB pages (8-byte entries, so each table is one 4 KB page)…
- A CPU-bound process and an I/O-bound process share a single CPU under a multilevel feedback queue with priority boosting. What is the…
- Two processes each need two printers, and the system has exactly 3 printers; each requests its printers one at a time and holds them until…