Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: Running stdin/out through a pipe to a child process Message-ID: <5104@mimsy.UUCP> Date: Sun, 18-Jan-87 11:45:09 EST Article-I.D.: mimsy.5104 Posted: Sun Jan 18 11:45:09 1987 Date-Received: Mon, 19-Jan-87 06:01:47 EST References: <136@cogent.UUCP> <3112@rsch.WISC.EDU> <423@bobkat.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 24 Keywords: fork, exec, pipes Xref: watmath comp.unix.questions:685 comp.unix.wizards:618 In article <423@bobkat.UUCP> m5d@bobkat.UUCP (Mike McNally) warns: >It is important for the parent to close the unused ends of the pipes for >a reason other than tidiness. If the child dies, the parent may want >to know. The system (BSD, at least) will send a SIGPIPE to the parent >if the child dies but the parent is still writing to the pipe AND the >child's copy of the descriptor is the only reader. If the parent's copy >of the read end is still open, the system will not deliver SIGPIPE. It is yet more important than that. As long as the parent still has open its chain to the read end of the pipe, the kernel will (having duly noted that there is *some* process out there that can read the pipe) eventually block the parent in a write() system call on the pipe until someone reads some of the data from that pipe. If the child dies or otherwise lets go of its own chain to the read end, only the (blocked) writer will be able to read enough data to unclog the pipe---but that writer can do nothing until someone unclogs the pipe! There *are* situations in which everything will work (the parent may write just a little bit, not blocking, then exit), but this is a bug just waiting to bite. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu