Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!ka From: ka@june.cs.washington.edu (Kenneth Almquist) Newsgroups: comp.unix.wizards Subject: Re: Shell scripts - getting parent status in read Summary: Reading a pipe with no writers returns EOF Message-ID: <7989@june.cs.washington.edu> Date: 25 Apr 89 19:25:10 GMT References: <861@marvin.Solbourne.COM> <849@twwells.uucp> <866@marvin.Solbourne.COM> Organization: U of Washington, Computer Science, Seattle Lines: 23 dce@Solbourne.COM (David Elliott) writes: > [A] read is being attempted on a pipe with [no one] on the other > side. I would think this would cause an EOF, and there was some > discussion on this recently, but it doesn't. It does cause an EOF, unless your UNIX is broken (which is unlikely). Probably you are forgetting to close the other end of the pipe. The way to set up a pipe to a child process (exclusive of error checking) is: pipe(pip); if (fork() == 0) { --> close(pip[1]); runchild(pip[0]); exit(0); } close(pip[0]); ... If you leave out the line that I've marked with an arrow, the child process will have both ends of the pipe open, so even when the parent terminates the child still won't get an EOF when it reads from the pipe. Kenneth Almquist