pipe equivalent to /dev/null ???

Chris Torek chris at mimsy.umd.edu
Mon Sep 17 02:09:00 AEST 1990


In article <13731 at ulysses.att.com> cjc at ulysses.att.com (Chris Calabrese)
writes:
>I've been following this thread for some time, and I have
>to say that neither '... | true' nor '... | :' will do the trick.
>I thought this would be obvious.

This much is correct, but:

>'true' and ':' don't read their stdin, thus the process feeding them
>would block and never run.

... several people have made this claim, and I cannot understand why.
Since this is going on in comp.unix.shell, and all the examples are
using shells, we can assume that the pipe is properly set up, i.e., the
process writing on it does not have it open for reading as well.  Since
`true' and `:' exit as soon as they are run, when the first process
first tries to write on the pipe it will get an error and a SIGPIPE
signal.

>A slightly better approach than '... | cat > /dev/null' is a trivial
>program which reads its input and creates no output.

Why is this better?  It saves one system call per pipe-read, but other
than that it takes more work and a separate program.  Writing to /dev/null
is very efficient (there are no user-to-kernel copies involved; indeed,
you can pass illegal addresses to write() if and only if you are writing
to /dev/null).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.shell mailing list