From owner-freebsd-questions Fri Sep 11 00:11:38 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA22793 for freebsd-questions-outgoing; Fri, 11 Sep 1998 00:11:38 -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 AAA22786 for ; Fri, 11 Sep 1998 00:11:34 -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 0zHNMX-00044T-00; Fri, 11 Sep 1998 07:11:22 +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 IAA01340; Fri, 11 Sep 1998 08:10:50 +0100 Received: from uk.radan.com (gppsun4) by beavis.uk.radan.com (4.1/SMI-4.1) id AA02287; Fri, 11 Sep 98 08:10:48 BST Message-Id: <35F8CCF1.B2BD199E@uk.radan.com> Date: Fri, 11 Sep 1998 08:10:41 +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: Leo Papandreou Cc: questions@FreeBSD.ORG Subject: Re: Help needed with fork(), pipe() & dup2() References: <35F6EE38.7DC97F21@uk.radan.com> <19980909182820.16714@talcom.net> <35F77884.E4FEAA21@uk.radan.com> <19980910173817.42597@talcom.net> <35F85DAF.2B23FC42@uk.radan.com> <19980911004700.52247@talcom.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Leo Papandreou wrote: > > > > > arg 2 in execvp() is a global char* that holds a list of filenames > > char **, you mean? Er yes, well it was late & I'd had a couple of beers.... > > > (delimited by \n and starts with "file", the name of the prog, and is > > terminated by a NULL) that the prog can't identify so it passes them to > > file(1) to try to id them. > > I'm not sure I understand the \n part. file(1) will interpret the > '\n' literally. Doh, I'd put in a for loop to printf() the contents of files for debugging, that was where I got \n from . Well it was late and..... > > > > > What puzzles me is that the Linux binary works OK under FreeBSD (2.2.7) > > Linux emulation. I'm building it with gcc 2.8.1. > > > > I've re-quoted the code below.... > > I rewrote foo() and embedded it into a short main() stub. It *did* > work under Linux but it only worked under FreeBSD for the first > call to foo(): > [code & output snipped] > > > What puzzles me is that the Linux binary works OK under FreeBSD (2.2.7) > > Linux emulation. I'm building it with gcc 2.8.1. > > > > Yeah, the above code produces the "expected" results on a RedHat machine. > I'd love to know why and where the difference in semantics lies. > So would I. I'm glad that someone else got the same results (at least I know it wasn't stupidity on my part). Surely using pipes for inter-process comms is a fairly standard construct so one would expect it to behave consistently across different flavours of Unix? > > I've re-quoted the code below.... > > > > Thanks for your help with this Leo. > > Thank Brian Sommers. His sol'n was correct. > > void foo() > { > > [...] > else if (pid > 0) > { /* parent */ > FILE *in; > > close(fd[1]); > if ((in = fdopen(fd[0], "r")) == NULL) > { > close(fd[0]); /* child gets SIGPIPE */ > err(1, NULL); > } That's another beer I owe Brian (he gave me a lot of patient help with ppp). It would appear that dup2() is the culprit as the only real change is using fdopen() instead of dup2(), but only for the parent, Brian's sol'n implies that dup2() still works in the child code. -- 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