But the effect is limited to just the process that called chroot and descendants of the current process. If the effect would be system wide, then all processes would see root as the new root, and be directed to the new password file and, among other things, be denied access to the system at the whim of the malicious user who called chroot. Shell forks a new process. New process does exec to start executing cc with the three parameters. Shell forks a new process.
New process does exec to start executing cc with three parameters.
There are several solutions, differing in the order of pipe and process creation. Here is one possibility. Shell creates the two pipes. Shell creates 3 processes, P1, P2, P3. P1, who will write to the first pipe, closes 1, dups the write side file descriptor, closes the read side file descriptor, closes the write side file descriptor, excecs in foo1.