This is how the shell in xv6 handles PIPE command (From xv6-source code).
8650 case PIPE:
8651 pcmd = (struct pipecmd*)cmd;
8652 if(pipe(p) < 0)
8653 panic("pipe");
8654 if(fork1() == 0){
8655 close(1);
8656 dup(p[1]);
8657 close(p[0]);
8658 close(p[1]);
8659 runcmd(pcmd−>left);
8660 }
8661 if(fork1() == 0){
8662 close(0);
8663 dup(p[0]);
8664 close(p[0]);
8665 close(p[1]);
8666 runcmd(pcmd−>right);
8667 }
8668 close(p[0]);
8669 close(p[1]);
8670 wait();
8671 wait();
8672 break;
And from my knowledge of fork, after the fork1() call in line 8661, there will be total 4 processes running. From the beginning, say the mother process is P. After the fork1() of line 8654, there are 2 processes, P and newly created C1. Both of them executes line 8661. So, 2 more new processes are created. C2 from P and C3 from C1.
But, for PIPE to work correctly, only C3 should execute line 8662 - 8666. Will process C2 not execute them? As C2 is a child process, I think it does. If it does, is that correct?