From owner-freebsd-questions Thu Sep 10 20:02:36 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA27868 for freebsd-questions-outgoing; Thu, 10 Sep 1998 20:02:36 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from awfulhak.org (awfulhak.force9.co.uk [195.166.136.63]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA27859 for ; Thu, 10 Sep 1998 20:02:28 -0700 (PDT) (envelope-from brian@Awfulhak.org) Received: from woof.lan.awfulhak.org (root@woof.lan.awfulhak.org [172.16.0.7]) by awfulhak.org (8.8.8/8.8.8) with ESMTP id BAA10263; Fri, 11 Sep 1998 01:56:25 +0100 (BST) (envelope-from brian@Awfulhak.org) Received: from woof.lan.awfulhak.org (brian@localhost [127.0.0.1]) by woof.lan.awfulhak.org (8.9.1/8.9.1) with ESMTP id BAA05212; Fri, 11 Sep 1998 01:54:57 +0100 (BST) (envelope-from brian@woof.lan.awfulhak.org) Message-Id: <199809110054.BAA05212@woof.lan.awfulhak.org> X-Mailer: exmh version 2.0.2 2/24/98 To: Mark Ovens cc: Brian Somers , questions@FreeBSD.ORG, freebsd-users@freebsd-uk.eu.org Subject: Re: Help needed with fork(), pipe() & dup2() In-reply-to: Your message of "Thu, 10 Sep 1998 07:50:18 BST." <35F776AA.9A256020@uk.radan.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 11 Sep 1998 01:54:52 +0100 From: Brian Somers Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG [.....] > 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. No. The gets() will block until either the other end of the pipe is close()d (at which point 0 is returned from the underlying read()) or until the other end of the pipe is written to. The parent should not be mucking around with STDIN and gets() at all. In my experience, way to many library calls use unexpected routines like err() and abort(). Besides, gets() produces warnings for a reason. Instead, change the parent if() block to FILE *in; int len; close(fd[1]); if ((in = fdopen(fd[0], "r")) == NULL) { close(fd[0]); /* child gets SIGPIPE */ vomit(); } line[sizoef line - 1] = '\0'; while (fgets(line, sizeof line - 1, in)) { len = strlen(line); if (len && line[len-1] == '\n') line[--len] = '\0'; . . . } fclose(in); close(fd[0]); > -- > 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 -- Brian , , Don't _EVER_ lose your sense of humour.... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message