Shell scripts - getting parent status in read

Kenneth Almquist ka at june.cs.washington.edu
Wed Apr 26 05:25:10 AEST 1989


dce at 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



More information about the Comp.unix.wizards mailing list