In a pipeline such as command1 | command2
,
- are the commands run simultaneously (i.e. have the same lifetime), or
- command2 starts to run at the time command1 exits, or
- something else?
My question arises when I heard that the commands' processes form a process group. If they don't have the same lifetime, isn't the process group of the commands' processes meaningless?
grep
does execute in the second example too. It just doesn't have much to do, because its input ends immediately. You can observe this by doing, e.g.cats and dogs | echo hello
, which will outputhello
, while complaining that there are no cats. The error message about the missing cats is being written to the first command's standard error stream, which is not redirected by default. But trycats and dogs 2>&1 | tr a u
– hmakholm left over Monica Apr 06 '15 at 01:42