Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: redirecting standard i/o from an exec'ed programme Message-ID: <7324@star.cs.vu.nl> Date: 16 Aug 90 18:53:10 GMT References: <377@fe2o3.UUCP> <410@sun13.scri.fsu.edu> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 29 In article <410@sun13.scri.fsu.edu>, mayne@VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) writes: )... ) /* Close unused pipes */ ) close (TOCHILD); ) close (FROMCHILD); ) /* Change stdin and stdout to pipe */ ) close(0); ) dup(FROMPARENT); close(FROMPARENT); /* !!! */ ) close(1); ) dup(TOPARENT); close(TOPARENT); /* !!! */ I've deleted the rest of the code, but there were still a few other places where calls to close() should be added. Always close every unused file descriptor (esp. when dealing with pipes), else you will get bitten one day; example scenario: - the child exits - the parent reads from the pipe to the child - the parent still has the write side of the pipe open - the read hangs... -- "UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." (Doug Gwyn)