Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!mips!sgi!shinobu!odin!sgihub!dragon!sam.wpd.sgi.com!pj From: pj@sam.wpd.sgi.com (Paul Jackson) Newsgroups: comp.sys.sgi Subject: Re: Problem with pipe/fork Message-ID: <1991Apr16.191706.3898@dragon.wpd.sgi.com> Date: 16 Apr 91 19:17:06 GMT References: <1991Apr16.150557.2344@jsp.umontreal.ca> Sender: news@dragon.wpd.sgi.com (CNews Account) Reply-To: pj@sgi.com Organization: Silicon Graphics, Research & Development Lines: 29 In article <1991Apr16.150557.2344@jsp.umontreal.ca>, gaumondp@JSP.UMontreal.CA (Gaumond Pierre) writes: [[ Sample program presented that has parent writing pipe to child. He asks why child doesn't notice EOF on the pipe after the parent closes it. ]] |> int fdi[2]; |> |> pipe(fdi); |> if (fork()!=0) { /* parent */ [[ Loops writing to fdi[1], then closes fdi[1]. ]] |> } else { /* child */ [[ Loops reading from fdi[0] until eof - but eof never seen. ]] |> } |> } In the child, before the loop until eof, add the line: close(fdi[1]); The fork resulted in both the parent and child having fdi[1] open for writing, and the child will see eof on fdi[0] only when all available writers to the pipe have closed the write end. -- I won't rest till it's the best ... Software Production Engineer Paul Jackson (pj@wpd.sgi.com), x1373