I've never really thought about how the shell actually executes piped commands. I've always been told that the "stdout of one program gets piped into the stdin of another," as a way of thinking about pipes. So naturally, I thought that in the case of say, A | BA | B, AA would run first, then BB gets the stdout of AA, and uses the stdout of AA as its input.
But I've noticed that when people search for a particular process in psps, they'd include grep -v "grep"grep -v "grep" at the end of the command to make sure that grepgrep doesn't appear in the final output.
This means that in the command ps aux | grep "bash" | grep -v "grep", which meansps aux | grep "bash" | grep -v "grep" it is implied that psps knew that grepgrep was running and therefore is in the output of psps. But if psps finishes running before its output gets piped to grepgrep, how did it know that grepgrep was running?
flamingtoast@FTOAST-UBUNTU: ~$ ps | grep ".*"
PID TTY TIME CMD
3773 pts/0 00:00:00 bash
3784 pts/0 00:00:00 ps
3785 pts/0 00:00:00 grep