Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: detect pipe

On Sun, Feb 14, 2021 at 12:33 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> If it is closed, where does input go?  Queued up or vanish?

File descriptors can be shared among processes.  Typically for example
the parent shell and any of its children will all have the same
standard input, unless there has been a redirection, including
creating a pipeline.

In the case of a pipeline, if ALL the processes that share a
descriptor have closed it, then the writer of the pipeline will get a
SIGPIPE signal.  The "input" (in this case, the output of the process
upstream in the pipeline) is neither queued nor vanishes; the attempt
to write fails and it's up to the writing process to decide how to
react to that, the default being for it to exit.

In the case of a file, the only affected process is the reader, which
gets "invalid file descriptor" if it attempts to read from stdin.

Messages sorted by: Reverse Date, Date, Thread, Author