Say we have a simple pipeline:
set -eo pipefail;
echo 'foo' | cat
how does cat
know when to exit? Is it when the STDIN stream ends, or does cat
receive a signal? In my case, the producer process receives a SIGINT and then exits with code 1, so how can cat
(consumer process) know which exit code the producer process exited with?
Best Answer
cat
doesn't know aboutecho
's signals. It receives end-of-file condition per man pipe(7):For writers to the pipe, however, there is SIGPIPE. See the same man page