The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Etymology of bc
@ 2014-09-13 11:53 Doug McIlroy
  0 siblings, 0 replies; only message in thread
From: Doug McIlroy @ 2014-09-13 11:53 UTC (permalink / raw)


> Speaking of using a pipe to an existing command, I originally mis-read the
> code to think there was only _one_ process involved, and that it was buffering
> its output into the pipe before doing the exec() itself - something like this:
> 
>         pipe(p);
>         write_stuff(p[1]);
>         close(0);
>         dup(p[0]);
>         close(p[0]);
>         close(p[1]);
>         execl("/bin/other", "other", arg, 0);
> 
> Which is kind of a hack, but... it does avoid using a second process, although
> the amount of data that can be passed is limited. (IIRC, a pipe will hold at
> most 8 blocks, at least on V6.) Did this hack ever get used in anything?

I didn't notice anybody commenting on the fact that this hack doesn't
work for the purpose--an interactive desk calculator. Running bc then
dc serially defeats interactivity.

The scheme of filling a pipe completely before emptying it is used
in Rob Pike's plan9 editor, sam, to pipe text through some transforming
process. Because the transformer (think sort) may not produce any
output until it has read all its input, sam can't read the result
back until it has finished stuffing the pipe.

Of course sam has to create two pipes, not just one, and it happens
that the initial writer and ultimate reader are the same. But the 
basic idea is the same.

Doug



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-09-13 11:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-13 11:53 [TUHS] Etymology of bc Doug McIlroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).