pipe/redirect dumb question
Erik Price
erikprice at mac.com
Wed Dec 11 22:41:52 EST 2002
On Wednesday, December 11, 2002, at 07:00 PM, jim.mcginness at att.net
wrote:
> An ordinary redirection opens a file descriptor with regular file
> semantics.
> Some shells implement "process" redirection which is similar to a pipe.
>
> The main difference between pipe file descriptors and "file" file
> descriptors
> is that pipes implement a sort of flow control. Draining a pipe causes
> the
> reader to block rather than receive an EOF. Filling up the pipe will
> cause
> the writer to block.
>
> Other differences are the way the file descriptors respond to various
> other
> syscalls. For instance, you can't do a 'seek' on a pipe.
Thanks for this comprehensive answer. Originally I asked this question
from a strictly pragmatic approach ("does it make a difference if I
pipe from a utility or redirect from a file, if it's the same data
either way"), but I had never considered the way piped data works.
Specifically that it causes the reader/writer to block depending on the
circumstances.
Does the code that tells the reader or writer to block have to be
written into the application, or is that somehow built into the shell?
If it needs to be built into the application, well then say for
instance I'm writing a Perl script. I've never programmed my Perl
script to block if the writer gets "full". So perhaps it's handled
internally by Perl. But if I'm writing a C program, I shouldn't make
the assumption that this will be done for me.
Unless of course I'm totally off the mark here, and the rules of piping
are handled by the shell or OS or something.
Erik
--
Erik Price (zombies roam)
email: erikprice at mac.com
jabber: erikprice at jabber.org
More information about the gnhlug-discuss
mailing list