From owner-freebsd-questions Wed Sep 9 23:51:07 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id XAA11741 for freebsd-questions-outgoing; Wed, 9 Sep 1998 23:51:07 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from post.mail.demon.net (post-12.mail.demon.net [194.217.242.41]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id XAA11736 for ; Wed, 9 Sep 1998 23:51:06 -0700 (PDT) (envelope-from marko@uk.radan.com) Received: from [158.152.75.22] (helo=uk.radan.com) by post.mail.demon.net with smtp (Exim 2.02 #1) id 0zH0ZC-0006Um-00; Thu, 10 Sep 1998 06:50:55 +0000 Organisation: Radan Computational Ltd., Bath, UK. Phone: +44-1225-320320 Fax: +44-1225-320311 Received: from beavis.uk.radan.com (beavis [193.114.228.122]) by uk.radan.com (8.6.10/8.6.10) with SMTP id HAA01220; Thu, 10 Sep 1998 07:50:27 +0100 Received: from uk.radan.com (gppsun4) by beavis.uk.radan.com (4.1/SMI-4.1) id AA00881; Thu, 10 Sep 98 07:50:26 BST Message-Id: <35F776AA.9A256020@uk.radan.com> Date: Thu, 10 Sep 1998 07:50:18 +0100 From: Mark Ovens Organization: Radan Computational Ltd X-Mailer: Mozilla 4.03 [en] (X11; I; SunOS 4.1.3_U1 sun4m) Mime-Version: 1.0 To: Brian Somers Cc: questions@FreeBSD.ORG, freebsd-users@freebsd-uk.eu.org Subject: Re: Help needed with fork(), pipe() & dup2() References: <199809100136.CAA05582@woof.lan.awfulhak.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Brian Somers wrote: > > [.....] > > while (gets (line) != NULL) > > { > > . > > . > > code to process "line" here > > . > > . > > } > > > > close (fd [0]); > ^^^^^^^^^^^^^^^ > Dodgy - fd[0] has already been closed (unless == STDIN_FILENO). > > > } /* parent */ > > else > > { /* child */ > > close (fd [0]); > > if (fd [1] != STDOUT_FILENO) > > { > > dup2(fd [1], STDOUT_FILENO) > > close (fd [1]); > > } > > if (execvp ("file", files) < 0) > > error_message (); > > close (fd [1]); > > Ditto, but this one (hopefully) doesn't normally happen. You're also > missing an exit() here. I did wonder about that. I tried commenting out the close() calls but it made no difference. I'll try adding exit() > > > } /* child */ > > } > > I don't know enough about the rest of the code to tell if that first > close may be the problem - but it *might*. Also, are you sure that > last error_message() isn't being called ? Definitely. It's an X program and the error_message function pops up a message window, and that definitely isn't happening. I got another reply suggesting that the problem is caused by the code assuming the order in which the parent & child execute, i.e. the parent reads the pipe (and sees NULL) before the child has written to it. This seems a very likely possiblity. > > -- > Brian , , > > Don't _EVER_ lose your sense of humour.... -- When everything's coming your way, you're in the wrong lane. Mark Ovens, CNC Applications Engineer, Radan Computational Ltd Sheet Metal CAD/CAM Solutions mailto:marko@uk.radan.com http://www.radan.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message