CS FundamentalsVery hardGATE CS · Product-company placement
f.txt does not exist at the start. Program X: fd = open("f.txt", O_WRONLY|O_CREAT, 0644); then fork(); the child writes "cd" and exits; the parent wait()s and then writes "ab" to fd. Program Y is the same except that the open() call is made separately by the child (before its write) and by the parent (after wait()). What does f.txt contain after each program?
- A. X: "ab"; Y: "ab"
- B. X: "cdab"; Y: "cdab"
- C. X: "cdab"; Y: "ab"
- D. X: "abcd"; Y: "ab"
Correct answer: C. X: "cdab"; Y: "ab"
In X the child inherits the same open-file description, so the file offset is shared: the child's write moves it to 2 and the parent appends, giving cdab. In Y each open() creates its own offset starting at 0, so the parent overwrites cd with ab.
More Operating Systems questions
- Cylinders 0–299; the head is at 140 and moving toward higher numbers. Requests: 45, 210, 160, 12, 275, 98, 130, 190. Which of SSTF and…
- A disk spins at 7200 RPM, has an average seek of 6 ms and 500 sectors of 512 bytes per track. A 1 MB file is read as 256 blocks of 4 KB…
- A Unix-style inode has 12 direct pointers, one single-indirect and one double-indirect pointer; blocks are 4 KB and block pointers 4…
- Six 4 TB disks are to be combined. Which layout survives ANY two simultaneous disk failures, and what usable capacity does it give?
- A 1 MB region uses the buddy system. Requests arrive for A = 70 KB, B = 35 KB and C = 80 KB. What is the total internal fragmentation, and…
- Free holes, in address order, are 150, 400, 250, 600 and 300 KB. Requests for 280, 200, 350 and 290 KB arrive in that order. Which…