From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Tue, 8 Dec 2009 01:13:04 +1100 From: Sam Watkins To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20091207141304.GA28905@nipl.net> References: <20091205031747.GA8759@nipl.net> <20091205194741.0697D5B76@mail.bitblocks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.13 (2006-08-11) Subject: Re: [9fans] ideas for helpful system io functions Topicbox-Message-UUID: a9f5ef9c-ead5-11e9-9d60-3106f5b1d025 On Mon, Dec 07, 2009 at 12:24:05PM +0000, roger peppe wrote: > if you wanted it, an "fd join" driver could be simply > implemented in a similar way: > > bind '#j4.5' /mnt/joined > open /mnt/joined/data to get a (read-only) fd that satisfies reads from fd 4 > until eof, then fd 5. That's not what I meant by joining two fds. I meant for example if a process is reading from its stdin a open file 'A' and writing to stdout the input of a pipe 'B', rather than looping and forwarding data it may simply "join" these two fds, and exit. The OS will then do what is necessary to make sure the data can travel from A to B (and/or vice versa) with the minimum effort needed. Supposing another process 'foo' is reading the other end of the pipe 'C', the OS will simply remove the pipe 'B-C' entirely, and reroute 'foo's stdin to come directly from 'A'. In other circumstances the OS might need to effectively exec 'cat' (or a 2-way socket-cat) to take over the task of copying data, but often it will be able to remove a pipe, reducing the amount of unnecessary copying that will take place. Where I have said "stdin" I mean the fds not stdio / buffered IO FILEs. I hope I've cleared up what I meant now, seems I'm not very good at explaining it. Sam