delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/03/22/13:21:45

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Thu, 22 Mar 2001 13:19:09 -0500
MIME-Version: 1.0
Subject: Re: pipe() emulation
Message-ID: <3AB9FBCD.21158.622AC9@localhost>
References: <3AB9425B DOT 11812 DOT 36ACFC AT localhost>
In-reply-to: <Pine.SUN.3.91.1010322100551.7564L-100000@is>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

> How is this supposed to be used?  Could you give an example of a
> real-life usage in Bash?

pipe() is used by the command substitution and pipeline portions of Bash. In 
the case of command substituion, Bash essentially does this:
pipe(fildes)
dup2(fildes[1], 1) /* write end of pipe now stdout */
/* perform command */
/* read command output from read end of pipe */

Pipelines such as 'a | b' are more complicated:
pipe(fildes1)
dup2(fildes1[1], 1) /* Write end of pipe 1 is now stdout */
/* run 'a' */
dup2(fildes1[0], 0) /* Read in of pipe 1 is now stdin */
close(fildes1[1]) /* Done with write end of pipe 1*/
/* run 'b' */
close(fildes1[0]) /* Done with read end of pipe 1 */


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019