CS FundamentalsModerateGATE CS (PYQ pattern)
A parent creates a pipe, forks, and the child loops on read(fd[0], buf, 1) until it returns 0. The parent writes 3 bytes into fd[1] and then calls wait() without closing either end of the pipe (neither does the child). What happens?
- A. The child reads the 3 bytes, gets 0 and exits, so wait() returns
- B. The child reads the 3 bytes and then blocks forever, so the parent also blocks in wait()
- C. The child gets 0 immediately because nothing is buffered yet
- D. The write fails with SIGPIPE because the child has the read end open
Correct answer: B. The child reads the 3 bytes and then blocks forever, so the parent also blocks in wait()
read returns 0 (EOF) only when every write end is closed. The parent still holds fd[1] (and the child inherited a copy), so after the data is consumed the read blocks; the parent's wait() then never returns: a classic deadlock.
More Operating Systems questions
- A system uses segmentation with paging (1024-byte pages). Segment table: seg 0: limit 3000, page frames [7, 2, 9]; seg 1: limit 1500…
- A process on a 4-level, 48-bit paging system (9 index bits per level, 4 KB pages, 4 KB page-table pages) maps three regions: 2 MB at…
- On a 4-level x86-64 style paging system (4 KB table pages, 512 eight-byte entries each, 2 MB pages are leaves at the third level), a…
- Polling a device costs a fixed 10% of the CPU (100,000 polls/s at 1 microsecond each) plus 0.5 microseconds of handling per event…
- In Lamport's bakery algorithm five processes P0 to P4 hold tickets (number, id): P0 has 4, P1 has 3, P2 has 4, P3 is not competing (0) and…
- A 200 KB heap is managed with a first-fit free list; adjacent free blocks are merged when memory is freed. Operations in order: alloc…